study_xxqg/utils/client.go

43 lines
830 B
Go
Raw Normal View History

package utils
import (
"net/http"
"github.com/imroc/req/v3"
log "github.com/sirupsen/logrus"
)
var client *req.Client
func init() {
client = req.C()
client.SetProxy(http.ProxyFromEnvironment)
if log.GetLevel() == log.DebugLevel {
client.DebugLog = true
client = client.DevMode()
}
client.EnableForceHTTP1()
client.SetLogger(&myLog{})
client.SetCommonHeader("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36")
}
func GetClient() *req.Client {
return client
}
type myLog struct {
}
func (m myLog) Errorf(format string, v ...interface{}) {
log.Errorf(format, v)
}
func (m myLog) Warnf(format string, v ...interface{}) {
log.Warnf(format, v)
}
func (m myLog) Debugf(format string, v ...interface{}) {
log.Debugf(format, v)
}