forked from storezhang/echox
-
Notifications
You must be signed in to change notification settings - Fork 1
/
option_proxy.go
53 lines (43 loc) · 1 KB
/
option_proxy.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
package echox
import (
`fmt`
`strings`
`github.com/storezhang/gox`
)
var _ option = (*optionProxy)(nil)
type optionProxy struct {
proxy string
}
// Proxy 配置代理
func Proxy(scheme gox.URIScheme, domain string, port int) *optionProxy {
var sb strings.Builder
sb.WriteString(fmt.Sprintf(`%s://%s`, scheme, domain))
// 处理默认端口
if gox.URISchemeHttps == scheme && 443 != port || gox.URISchemeHttp == scheme && 80 != port {
sb.WriteString(fmt.Sprintf(`:%d`, port))
}
return &optionProxy{
proxy: sb.String(),
}
}
// ProxyAddr 配置代理
func ProxyAddr(addr string) *optionProxy {
return &optionProxy{
proxy: addr,
}
}
// HttpProxy 配置Http代理
func HttpProxy(domain string) *optionProxy {
return &optionProxy{
proxy: fmt.Sprintf(`http://%s`, domain),
}
}
// HttpsProxy 配置Https代理
func HttpsProxy(domain string) *optionProxy {
return &optionProxy{
proxy: fmt.Sprintf(`https://%s`, domain),
}
}
func (p *optionProxy) apply(options *options) {
options.proxy = p.proxy
}