-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
45 lines (34 loc) · 936 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"encoding/json"
"flag"
"fmt"
"github.com/monaco-io/request"
)
type Snippet struct {
URN string `json:"urn"`
Syntax string `json:"syntax"`
Description string `json:"description"`
Content string `json:"content"`
}
func main() {
syntax := flag.String("syntax", "", "Syntax Used")
description := flag.String("desc", "", "Description")
content := flag.String("content", "", "Code")
flag.Parse()
snippet := new(Snippet)
snippet.Syntax = *syntax
snippet.Description = *description
snippet.Content = *content
snippetJSON, _ := json.Marshal(snippet)
client := request.Client{
URL: "http://localhost:8000/api/snippet/",
Method: "POST",
Body: snippetJSON,
}
resp, _ := client.Do()
var snippetResponse Snippet
json.Unmarshal(resp.Data, &snippetResponse)
url := fmt.Sprintf("http://localhost:8000/api/snippet/%s/\n", string(snippetResponse.URN))
fmt.Printf(url)
}