-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
82 lines (70 loc) · 1.91 KB
/
options.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
package sat
import (
"log"
"net/http"
"github.com/tokopedia/golang-sat/signature"
)
// Option contains field you can configure based on your SAT credentials
type Option struct {
http *http.Client
logger *log.Logger
clientID string
clientSecret string
clientPrivateKey string
serverPublicKey string
paddingType signature.PaddingType
isDebug bool
accessTokenURL string
satBaseURL string
}
var defaultOption = Option{
http: &http.Client{},
logger: log.New(log.Writer(), "[sat] ", 0),
paddingType: signature.PaddingTypePSS,
isDebug: false,
accessTokenURL: ACCESS_TOKEN_URL,
satBaseURL: PLAYGROUND_SAT_BASE_URL,
}
type ClientOptionFunc func(*Option)
// WithHTTPClient customizes http client
func WithHTTPClient(httpClient *http.Client) ClientOptionFunc {
return func(o *Option) {
o.http = httpClient
}
}
// WithLogger override existing logger
func WithLogger(logger *log.Logger) ClientOptionFunc {
return func(o *Option) {
o.logger = logger
}
}
// WithServerPublicKeyString load server public key
func WithServerPublicKeyString(serverPublicKey string) ClientOptionFunc {
return func(o *Option) {
o.serverPublicKey = serverPublicKey
}
}
// WithPaddingType set specific padding type for sign & verify signature
func WithPaddingType(paddingType signature.PaddingType) ClientOptionFunc {
return func(o *Option) {
o.paddingType = paddingType
}
}
// WithIsDebug is toggle debug log
func WithIsDebug(isDebug bool) ClientOptionFunc {
return func(o *Option) {
o.isDebug = isDebug
}
}
// WithSatBaseURL override SAT Base URL
func WithSatBaseURL(satBaseURL string) ClientOptionFunc {
return func(o *Option) {
o.satBaseURL = satBaseURL
}
}
// WithAccessTokenURL WithSatBaseURL override SAT Base URL
func WithAccessTokenURL(accessTokenURL string) ClientOptionFunc {
return func(o *Option) {
o.accessTokenURL = accessTokenURL
}
}