-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathovo.go
74 lines (67 loc) · 1.53 KB
/
ovo.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 ovo
import (
"net/http"
"time"
)
// Client is ovo client.
type Client struct {
appID string
key string
tid string
mid string
merchantID string
storeCode string
baseURL string
requester Requester
logger Logger
}
// Option is config for ovo client.
type Option struct {
AppID string
Key string
TID string
MID string
MerchantID string
StoreCode string
BaseURL string
Requester Requester
Logger Logger
}
// New to create new ovo client with config.
func New(option Option) *Client {
if option.Logger == nil {
option.Logger = defaultLogger(LogError)
}
if option.Requester == nil {
option.Requester = defaultRequester(&http.Client{
Timeout: 70 * time.Second,
}, option.Logger)
}
return &Client{
appID: option.AppID,
key: option.Key,
tid: option.TID,
mid: option.MID,
merchantID: option.MerchantID,
storeCode: option.StoreCode,
baseURL: option.BaseURL,
requester: option.Requester,
logger: option.Logger,
}
}
// NewDefault to create new ovo client with default config.
func NewDefault(appID, key, tid, mid, merchantID, storeCode string, env EnvironmentType) *Client {
return New(Option{
AppID: appID,
Key: key,
TID: tid,
MID: mid,
MerchantID: merchantID,
StoreCode: storeCode,
BaseURL: envURL[env],
Requester: defaultRequester(&http.Client{
Timeout: 70 * time.Second,
}, defaultLogger(envLog[env])),
Logger: defaultLogger(envLog[env]),
})
}