-
Notifications
You must be signed in to change notification settings - Fork 0
/
actions.go
47 lines (43 loc) · 999 Bytes
/
actions.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
package main
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
)
// Get is a function to do a get request
func Get(link string) ([]byte, error) {
fmt.Println("Do get request")
req, err := http.NewRequest("GET", link, nil)
req.Header.Add("If-None-Match", `W/"wyzzy"`)
resp, err := client.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
return body, err
}
// Post is a function to do a post request
func Post(link string, ctnType string, values string) ([]byte, error) {
if ctnType == "" {
ctnType = "application/json"
}
fmt.Println("Do post request")
req, err := http.NewRequest("POST", link, bytes.NewBuffer([]byte(values)))
req.Header.Set("Content-Type", ctnType)
resp, err := client.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
if err != nil {
return nil, err
}
return body, err
}