From 5aba05d7237c2250e647a717f8abef658f30a9e9 Mon Sep 17 00:00:00 2001 From: Keuin Date: Sat, 1 Jul 2023 22:02:01 +0800 Subject: Refactor: replace homemade error type checking with idiom Go practices. --- bilibili/request.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'bilibili/request.go') diff --git a/bilibili/request.go b/bilibili/request.go index feb2b8f..2e4b57e 100644 --- a/bilibili/request.go +++ b/bilibili/request.go @@ -2,7 +2,6 @@ package bilibili import ( "encoding/json" - "github.com/keuin/slbr/common" "io" "net" "net/http" @@ -77,9 +76,8 @@ func (b Bilibili) Do(req *http.Request) (resp *http.Response, err error) { transport.DialContext = netCtx b.http.Transport = transport resp, err = b.http.Do(req) - - isOpErr := common.IsErrorOfType(err, &net.OpError{}) - isAddrErr := common.IsErrorOfType(err, &net.AddrError{}) + _, isOpErr := err.(*net.OpError) + _, isAddrErr := err.(*net.AddrError) if err == nil || !isOpErr || !isAddrErr { // return the first success request b.logger.Info("Request success with network %v.", typeName) -- cgit v1.2.3