/
dashboardmeta.go
52 lines (49 loc) · 1.46 KB
/
dashboardmeta.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
package models
import (
"crypto/tls"
"encoding/base64"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
)
type Dashboard struct {
Id int `json:"id"`
Uid string `json:"uid"`
Title string `json:"title"`
Uri string `json:"uri"`
Slug string `json:"slug"`
Type string `json:"type"`
Tags []string `json:"tags"`
IsStarred bool `json:"isStarred"`
SortMeta int `json:"sortMeta"`
}
func ListDashboards(b *Backup) []Dashboard {
var ListDashboards []Dashboard
req, err := http.NewRequest("GET", b.Url+"/api/search?dashboardIds", nil)
if err != nil {
log.Println("Error on newrequest.\n[ERROR] -", err)
}
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
autorizacao := base64.StdEncoding.EncodeToString([]byte(b.Login + ":" + b.Password))
fmt.Println(autorizacao)
req.Header.Add("Authorization", "Basic "+autorizacao)
req.Header.Add("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
log.Println("Error on response.\n[ERROR] -", err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Println("Error while reading the response bytes:", err)
}
// log.Println(string([]byte(body)))
err = json.Unmarshal(body, &ListDashboards)
if err != nil {
log.Println("Error while on unMarshal:", err)
}
return ListDashboards
}