-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.go
58 lines (46 loc) · 1.07 KB
/
app.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
package go_nifi_api
import (
"crypto/tls"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"strings"
)
type app struct {
host string
client *http.Client
}
const api = "nifi-api"
func (a *app) Do(url, token, method string, data url.Values) ([]byte, error) {
var req *http.Request = nil
var err error
req, err = http.NewRequest(method, url, strings.NewReader(data.Encode()))
if err != nil {
return nil, err
}
if token == "" {
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
} else {
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", token))
}
response, _ := a.client.Do(req)
defer response.Body.Close()
read, _ := ioutil.ReadAll(response.Body)
return []byte(read), nil
}
func (a *app) initialization() {
// Create New http Transport
transCfg := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, // disable verify
}
// Create Http Client
a.client = &http.Client{
Transport: transCfg,
}
}
func NewNiFi(host string) *app {
app := app{host: fmt.Sprintf("%s/%s", host, api)}
app.initialization()
return &app
}