feat: 🚛 完成了 client 资源创建

This commit is contained in:
zhaoyupeng
2025-12-31 17:31:25 +08:00
parent 0bcb138fd5
commit eb87d6fbed
20 changed files with 632 additions and 60 deletions

40
pkg/tool/client/http.go Normal file
View 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
}