generated from storezhang/template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagent.go
50 lines (42 loc) · 916 Bytes
/
agent.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
package wanip
import (
"github.com/go-resty/resty/v2"
"github.com/goexl/simaqian"
)
var _ = New
// Agent 执行机器人
type Agent struct {
client *resty.Client
logger simaqian.Logger
options *options
}
// New 创建执行机器人
func New(opts ...option) (agent *Agent, err error) {
agent = new(Agent)
agent.options = defaultOptions()
for _, opt := range opts {
opt.apply(agent.options)
}
if nil == agent.options.logger {
agent.logger, err = simaqian.New()
} else {
agent.logger = agent.options.logger
}
if nil == agent.options.client {
agent.client = resty.New()
} else {
agent.client = agent.options.client
}
return
}
func (a *Agent) Get(opts ...getOption) (ip string, err error) {
_options := defaultGetOptions()
for _, opt := range opts {
opt.applyGet(_options)
}
switch _options.mode {
case modeIpv4:
ip, err = a.options.provider.ipv4.ipv4(a.client)
}
return
}