feat: 🚛 完成了 client 资源创建
This commit is contained in:
40
pkg/tool/client/http.go
Normal file
40
pkg/tool/client/http.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
type HttpClientOption func(*httpClientOption)
|
||||
type httpClientOption struct {
|
||||
SkipTLSVerify bool
|
||||
Proxy string
|
||||
}
|
||||
|
||||
func HttpClient(opts ...HttpClientOption) *http.Client {
|
||||
var (
|
||||
o = &httpClientOption{}
|
||||
t = &http.Transport{}
|
||||
)
|
||||
|
||||
for _, fn := range opts {
|
||||
fn(o)
|
||||
}
|
||||
|
||||
if o.SkipTLSVerify {
|
||||
t.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
|
||||
}
|
||||
|
||||
if o.Proxy != "" {
|
||||
if ins, err := url.Parse(o.Proxy); err == nil {
|
||||
t.Proxy = http.ProxyURL(ins)
|
||||
}
|
||||
}
|
||||
|
||||
c := &http.Client{
|
||||
Transport: t,
|
||||
}
|
||||
|
||||
return c
|
||||
}
|
||||
Reference in New Issue
Block a user