forked from whyiyhw/go-workwx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_options.go
64 lines (49 loc) · 1.04 KB
/
client_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
package workwx
import (
"net/http"
)
// DefaultQYAPIHost 默认企业微信 API Host
const DefaultQYAPIHost = "https://qyapi.weixin.qq.com"
type options struct {
QYAPIHost string
HTTP *http.Client
}
// CtorOption 客户端对象构造参数
type CtorOption interface {
applyTo(*options)
}
// impl Default for options
func defaultOptions() options {
return options{
QYAPIHost: DefaultQYAPIHost,
HTTP: &http.Client{},
}
}
//
//
//
type withQYAPIHost struct {
x string
}
// WithQYAPIHost 覆盖默认企业微信 API 域名
func WithQYAPIHost(host string) CtorOption {
return &withQYAPIHost{x: host}
}
var _ CtorOption = (*withQYAPIHost)(nil)
func (x *withQYAPIHost) applyTo(y *options) {
y.QYAPIHost = x.x
}
//
//
//
type withHTTPClient struct {
x *http.Client
}
// WithHTTPClient 使用给定的 http.Client 作为 HTTP 客户端
func WithHTTPClient(client *http.Client) CtorOption {
return &withHTTPClient{x: client}
}
var _ CtorOption = (*withHTTPClient)(nil)
func (x *withHTTPClient) applyTo(y *options) {
y.HTTP = x.x
}