代码拉取完成,页面将自动刷新
package proxy
import (
"time"
)
// Option is an interface that specifies instrumentation configuration options.
type Option interface {
apply(*config)
}
// optionFunc is a type of function that can be used to implement the Option interface.
// It takes a pointer to a config struct and modifies it.
type optionFunc func(*config)
// Ensure that optionFunc satisfies the Option interface.
var _ Option = (*optionFunc)(nil)
// The apply method of optionFunc type is implemented here to modify the config struct based on the function passed.
func (o optionFunc) apply(c *config) {
o(c)
}
// WithProxyURL is a function that returns an Option, which sets the proxyURL field of the config struct.
func WithProxyURL(val string) Option {
return optionFunc(func(c *config) {
c.proxyURL = val
})
}
// WithSocksURL is a function that returns an Option, which sets the socksURL field of the config struct.
func WithSocksURL(val string) Option {
return optionFunc(func(c *config) {
c.socksURL = val
})
}
// WithTimeout returns a new Option that sets the timeout for the client configuration.
// It takes a time.Duration value representing the timeout duration.
// It returns an optionFunc that sets the timeout field of the configuration to the provided value.
func WithTimeout(val time.Duration) Option {
return optionFunc(func(c *config) {
c.timeout = val
})
}
// WithHeaders returns a new Option that sets the headers for the http client configuration.
func WithHeaders(headers []string) Option {
return optionFunc(func(c *config) {
c.headers = headers
})
}
// WithSkipVerify returns a new Option that sets the insecure flag for the http client configuration.
func WithSkipVerify(insecure bool) Option {
return optionFunc(func(c *config) {
c.insecure = insecure
})
}
// config is a struct that stores configuration options for the instrumentation.
type config struct {
proxyURL string
socksURL string
timeout time.Duration
insecure bool
headers []string
}
// newConfig creates a new config object with default values, and applies the given options.
func newConfig(opts ...Option) *config {
// Create a new config object with default values.
c := &config{
timeout: 30 * time.Second,
insecure: false,
}
// Apply each of the given options to the config object.
for _, opt := range opts {
opt.apply(c)
}
// Return the resulting config object.
return c
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。