-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnection.go
61 lines (56 loc) · 1.22 KB
/
connection.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
package main
import (
"crypto/tls"
"fmt"
driver "github.com/arangodb/go-driver"
"github.com/arangodb/go-driver/http"
)
type ClientParams struct {
Host string
Port string
User string
Pass string
IsSecure bool
}
func getClient(p *ClientParams) (driver.Client, error) {
var client driver.Client
var conn driver.Connection
host := p.Host
port := p.Port
user := p.User
pass := p.Pass
isSecure := p.IsSecure
if isSecure {
c, err := http.NewConnection(
http.ConnectionConfig{
Endpoints: []string{
fmt.Sprintf("https://%s:%s", host, port),
},
TLSConfig: &tls.Config{InsecureSkipVerify: true},
})
if err != nil {
return client, fmt.Errorf("could not connect %s", err)
}
conn = c
} else {
c, err := http.NewConnection(
http.ConnectionConfig{
Endpoints: []string{
fmt.Sprintf("http://%s:%s", host, port),
},
})
if err != nil {
return client, fmt.Errorf("could not connect %s", err)
}
conn = c
}
client, err := driver.NewClient(
driver.ClientConfig{
Connection: conn,
Authentication: driver.BasicAuthentication(user, pass),
})
if err != nil {
return client, fmt.Errorf("could not get a client instance %s", err)
}
return client, nil
}