-
Notifications
You must be signed in to change notification settings - Fork 3
/
options_with.go
67 lines (58 loc) · 1.53 KB
/
options_with.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
package proxyKit
import (
"log"
"net/http"
)
func WithScheme(scheme string) ProxyOption {
return func(opts *proxyOptions) {
opts.scheme = scheme
}
}
func WithErrorLogger(errorLogger *log.Logger) ProxyOption {
return func(opts *proxyOptions) {
opts.errorLogger = errorLogger
}
}
// WithRequestUrlPath
/*
PS: 如果 当前路由 和 目标路由 一致,可以不配置此项;否则必须配置.
@param requestUrlPath (1) 不带query;
(2) 可以使用 ptrKit.Of() 生成 *string 实例.
*/
func WithRequestUrlPath(requestUrlPath *string) ProxyOption {
return func(opts *proxyOptions) {
opts.requestUrlPath = requestUrlPath
}
}
// WithOverrideQueryParams
/*
PS:
(1) WithOverrideQueryParams 和 WithExtraQueryParams 只能二选一.
(2) 值不用进行编码处理.
*/
func WithOverrideQueryParams(overrideQueryParams map[string][]string) ProxyOption {
return func(opts *proxyOptions) {
opts.overrideQueryParams = overrideQueryParams
}
}
// WithExtraQueryParams
/*
PS:
(1) WithOverrideQueryParams 和 WithExtraQueryParams 只能二选一.
(2) 值不用进行编码处理.
*/
func WithExtraQueryParams(extraQueryParams map[string][]string) ProxyOption {
return func(opts *proxyOptions) {
opts.extraQueryParams = extraQueryParams
}
}
func WithPolyfillHeaders(polyfillHeaders bool) ProxyOption {
return func(opts *proxyOptions) {
opts.polyfillHeaders = polyfillHeaders
}
}
func WithModifyResponse(modifyResponse func(*http.Response) error) ProxyOption {
return func(opts *proxyOptions) {
opts.modifyResponse = modifyResponse
}
}