-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
60 lines (51 loc) · 892 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"net/http"
"fmt"
"bytes"
"io/ioutil"
"os"
)
// Read url.txt
func loadDestination() (url string) {
f, err := os.Open("url.txt")
if err != nil {
fmt.Print("Erorr")
}
defer f.Close()
txt, _ := ioutil.ReadAll(f)
url = string(txt)
return url
}
// send http request
func post(userin, url string) error {
jsonStr := `{"content":"` + userin + `"}`
req, err := http.NewRequest(
"POST",
url,
bytes.NewBuffer([]byte(jsonStr)),
)
if err != nil {
return err
}
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
return err
}
func main() {
var userin string
var url string
url = loadDestination()
fmt.Scan(&userin)
resp := post(userin, url)
if resp != nil {
fmt.Println(resp)
} else {
fmt.Print("Send your message!")
}
}