-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathinternal.go
84 lines (66 loc) · 1.52 KB
/
internal.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package goconfluence
import (
"crypto/tls"
"errors"
"fmt"
"net/http"
"net/url"
)
var (
errEmptyHTTPClient = errors.New("empty http client")
)
// NewAPI implements API constructor
func NewAPI(location string, username string, token string) (*API, error) {
if len(location) == 0 {
return nil, errors.New("url empty")
}
u, err := url.ParseRequestURI(location)
if err != nil {
return nil, err
}
a := new(API)
a.endPoint = u
a.token = token
a.username = username
// #nosec G402
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: false},
}
a.Client = &http.Client{Transport: tr}
return a, nil
}
// NewAPIWithClient creates a new API instance using an existing HTTP client.
// Useful when using oauth or other authentication methods.
func NewAPIWithClient(location string, client *http.Client) (*API, error) {
u, err := url.ParseRequestURI(location)
if err != nil {
return nil, err
}
if client == nil {
return nil, errEmptyHTTPClient
}
a := new(API)
a.endPoint = u
a.Client = client
return a, nil
}
// VerifyTLS to enable disable certificate checks
func (a *API) VerifyTLS(set bool) {
// #nosec G402
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: !set},
}
a.Client = &http.Client{Transport: tr}
}
// DebugFlag is the global debugging variable
var DebugFlag = false
// SetDebug enables debug output
func SetDebug(state bool) {
DebugFlag = state
}
// Debug outputs debug messages
func Debug(msg interface{}) {
if DebugFlag {
fmt.Printf("%+v\n", msg)
}
}