summaryrefslogtreecommitdiff
path: root/bilibili/client.go
diff options
context:
space:
mode:
Diffstat (limited to 'bilibili/client.go')
-rw-r--r--bilibili/client.go28
1 files changed, 24 insertions, 4 deletions
diff --git a/bilibili/client.go b/bilibili/client.go
index fcea395..8097115 100644
--- a/bilibili/client.go
+++ b/bilibili/client.go
@@ -7,6 +7,7 @@ package bilibili
import (
"context"
"log"
+ "net"
"net/http"
"os"
)
@@ -21,25 +22,44 @@ type Bilibili struct {
userAgent string
http *http.Client
loggerCommon
- ctx context.Context
+ ctx context.Context
+ netTypes []IpNetType
}
-func NewBilibiliWithContext(ctx context.Context) Bilibili {
+func NewBilibiliWithContext(ctx context.Context, netTypes []IpNetType) Bilibili {
logger := loggerCommon{
debug: log.New(os.Stderr, "DEBUG: ", log.Ldate|log.Ltime|log.Lshortfile),
info: log.New(os.Stderr, "INFO: ", log.Ldate|log.Ltime|log.Lshortfile),
warn: log.New(os.Stderr, "WARNING: ", log.Ldate|log.Ltime|log.Lshortfile),
error: log.New(os.Stderr, "ERROR: ", log.Ldate|log.Ltime|log.Lshortfile),
}
+
+ var nets []IpNetType
+ nets = append(nets, netTypes...)
+ if len(nets) == 0 {
+ nets = append(nets, IP64)
+ }
+
+ var dialer net.Dialer
+ np := newNetProbe(nets)
+ transport := http.DefaultTransport.(*http.Transport).Clone()
+ transport.DialTLSContext = nil
+ transport.DialContext, _ = np.NextNetworkType(dialer)
+
return Bilibili{
loggerCommon: logger,
userAgent: kUserAgent,
http: http.DefaultClient,
ctx: ctx,
+ netTypes: nets,
}
}
-func NewBilibili() Bilibili {
+func NewBilibiliWithNetType(netTypes []IpNetType) Bilibili {
ctx := context.Background()
- return NewBilibiliWithContext(ctx)
+ return NewBilibiliWithContext(ctx, netTypes)
+}
+
+func NewBilibili() Bilibili {
+ return NewBilibiliWithNetType(nil)
}