-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
58 lines (47 loc) · 1.02 KB
/
main.go
File metadata and controls
58 lines (47 loc) · 1.02 KB
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
package main
import (
"crypto/tls"
"fmt"
"io"
"net/http"
"github.com/thedevsaddam/gojsonq"
)
var (
url = "https://xxxxxxx"
auth = "Bearer xxxxxxxx"
action = "GET"
transport = &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}
client = &http.Client{Transport: transport}
)
// appel de l'api
func callApi(api_action, api_url, api_auth string) (string, error) {
// create request
req, err := http.NewRequest(api_action, api_url, nil)
if err != nil {
return "", err
}
// set auth
req.Header.Add("Authorization", api_auth)
resp, err := client.Do(req)
if err != nil {
return "", err
}
defer resp.Body.Close()
// get response
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
}
return string(bodyBytes), nil
}
func main() {
str, err := callApi(action, url, auth)
if err != nil {
fmt.Println(err)
return
}
// SAMPLE
jq := gojsonq.New().JSONString(str).From("FOO").WhereEqual("BAR", true).Find("[0].USER.NAME")
// print
fmt.Println(jq)
}