-
Notifications
You must be signed in to change notification settings - Fork 50
/
request.go
44 lines (34 loc) · 1.06 KB
/
request.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
package gokong
import (
"crypto/tls"
"github.com/parnurzeal/gorequest"
)
func configureRequest(r *gorequest.SuperAgent, config *Config) *gorequest.SuperAgent {
r.TLSClientConfig(&tls.Config{InsecureSkipVerify: config.InsecureSkipVerify})
if config.Username != "" || config.Password != "" {
r.SetBasicAuth(config.Username, config.Password)
}
if config.ApiKey != "" {
r.Set("apikey", config.ApiKey)
}
if config.AdminToken != "" {
r.Set("kong-admin-token", config.AdminToken)
}
return r
}
func newGet(config *Config, address string) *gorequest.SuperAgent {
r := gorequest.New().Get(address)
return configureRequest(r, config)
}
func newPost(config *Config, address string) *gorequest.SuperAgent {
r := gorequest.New().Post(address)
return configureRequest(r, config)
}
func newPatch(config *Config, address string) *gorequest.SuperAgent {
r := gorequest.New().Patch(address)
return configureRequest(r, config)
}
func newDelete(config *Config, address string) *gorequest.SuperAgent {
r := gorequest.New().Delete(address)
return configureRequest(r, config)
}