可以通过定义一个新的函数来设置TLSClientConfig:

func WithTLSClientConfig(config *tls.Config) Opt {
	return func(c *Client) error {
		c.tlsClientConfig = config
		return nil
	}
}

然后在使用WithHTTPHeaders函数时,同时调用WithTLSClientConfig函数来设置TLSClientConfig:

headers := map[string]string{
	"Authorization": "Bearer token",
}

tlsConfig := &tls.Config{
	InsecureSkipVerify: false,
}

opts := []Opt{
	WithHTTPHeaders(headers),
	WithTLSClientConfig(tlsConfig),
}

client := NewClient(opts...)
func WithHTTPHeadersheaders mapstringstring Opt 	return funcc Client error 		ccustomHTTPHeaders = headers		return nil	如何设置TLSClientConfig &tlsConfigInsecureSkipVerify false

原文地址: https://www.cveoy.top/t/topic/hYIO 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录