-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfineract_client.go
67 lines (58 loc) · 1.27 KB
/
fineract_client.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
package fineract
import (
"crypto/tls"
"log"
"net/http"
"net/url"
"sync"
)
const (
fineractHost = "13.209.34.65:8443" //"https://demo.openmf.org"
fineractUser = "mifos"
fineractPassword = "password"
)
type Transporter interface {
Do(req *http.Request) (*http.Response, error)
}
type FineractOption struct {
Transport Transporter
SkipVerify bool
}
type Client struct {
HostName *url.URL
UserName string
Password string
Option FineractOption
}
var once sync.Once
var client Client
func NewClient(hostName, userName, password string, option FineractOption) (*Client, error) {
host, err := url.Parse(hostName)
if err != nil {
log.Println(err)
return nil, err
}
once.Do(func() {
if option.Transport == nil {
httpClient := http.Client{}
if option.SkipVerify == true {
httpClient.Transport = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
}
option.Transport = &httpClient
}
client = Client{
HostName: host,
UserName: userName,
Password: password,
Option: option,
}
})
return &client, err
}
func NewMockClient() (*Client, error) {
return NewClient("https://"+fineractHost, fineractUser, fineractPassword, FineractOption{
Transport: &MockTransport{DirectoryPath: "../testdata"},
})
}