forked from Virtomize/confluence-go-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinternal.go
74 lines (58 loc) · 1.43 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
package goconfluence
import (
"crypto/tls"
"errors"
"fmt"
"net/http"
"net/url"
)
// NewAPI implements API constructor
func NewAPI(location string, username string, token string) (*API, error) {
if len(location) == 0 || len(username) == 0 || len(token) == 0 {
return nil, errors.New("url, username or token empty")
}
u, err := url.ParseRequestURI(location)
if err != nil {
return nil, err
}
a := new(API)
a.endPoint = u
a.token = token
a.username = username
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
}
a := new(API)
a.endPoint = u
a.client = client
return a, nil
}
// VerifyTLS to enable disable certificate checks
func (a *API) VerifyTLS(set bool) {
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)
}
}