- update version

master
dtapps 4 months ago
parent ad80d76806
commit df7b50a63a

@ -2,7 +2,7 @@
<a href="https://www.dtapp.net/">Golang</a>
</h1>
📦 Golang Request
📦 Golang 请求
[comment]: <> (go)
[![godoc](https://pkg.go.dev/badge/go.dtapp.net/gorequest?status.svg)](https://pkg.go.dev/go.dtapp.net/gorequest)
@ -13,7 +13,7 @@
#### 安装
```shell
go get -v -u go.dtapp.net/gorequest@v1.0.43
go get -v -u go.dtapp.net/gorequest@v1.0.44
```
#### 使用

@ -1,8 +1,8 @@
package gorequest
import (
"fmt"
"github.com/shirou/gopsutil/host"
"log"
"runtime"
)
@ -13,26 +13,18 @@ type systemResult struct {
// 获取系统信息
func getSystem() (result systemResult) {
hInfo, err := host.Info()
if err != nil {
log.Printf("getSystem.host.Info%s\n", err)
}
hInfo, _ := host.Info()
result.SystemOs = hInfo.OS
result.SystemKernel = hInfo.KernelArch
return result
}
// 设置配置信息
func (app *App) setConfig() {
info := getSystem()
app.config.systemOs = info.SystemOs
app.config.systemKernel = info.SystemKernel
app.config.goVersion = runtime.Version()
app.config.sdkVersion = Version
app.config.sdkUserAgent = fmt.Sprintf(userAgentFormat1, app.config.systemOs, app.config.systemKernel, app.config.goVersion)
}

@ -1,7 +1,8 @@
package gorequest
const (
userAgentFormat = "%s/%s/%s/%s"
userAgentFormat1 = "%s/%s/%s"
userAgentFormat2 = "%s/%s/%s/%s"
)
// 定义请求类型

@ -56,6 +56,8 @@ type App struct {
systemOs string // 系统类型
systemKernel string // 系统内核
goVersion string // go版本
sdkVersion string // sdk版本
sdkUserAgent string // sdk用户代理
}
}
@ -107,7 +109,7 @@ func (app *App) SetAuthToken(token string) {
app.httpHeader.Set("Authorization", fmt.Sprintf("Bearer %s", token))
}
// SetUserAgent 设置用户代理,空字符串就随机设置
// SetUserAgent 设置用户代理,空字符串就随机设置
func (app *App) SetUserAgent(ua string) {
if ua == "" {
ua = GetRandomUserAgent()
@ -115,6 +117,15 @@ func (app *App) SetUserAgent(ua string) {
app.httpHeader.Set("User-Agent", ua)
}
// SetPassSdkVersion 传入SDK版本
func (app *App) SetPassSdkVersion(sdkVersion string) {
if sdkVersion == "" {
app.httpHeader.Set("Sdk-User-Agent", app.config.sdkUserAgent)
} else {
app.httpHeader.Set("Sdk-User-Agent", fmt.Sprintf(userAgentFormat2, app.config.systemOs, app.config.systemKernel, app.config.goVersion, sdkVersion))
}
}
// SetContentTypeJson 设置JSON格式
func (app *App) SetContentTypeJson() {
app.httpContentType = httpParamsModeJson
@ -230,7 +241,9 @@ func request(app *App, ctx context.Context) (httpResponse Response, err error) {
}
// SDK版本
//httpResponse.RequestHeader.Set("Sdk-User-Agent", fmt.Sprintf(userAgentFormat, app.config.systemOs, app.config.systemKernel, app.config.goVersion))
if app.config.sdkUserAgent != "" {
httpResponse.RequestHeader.Set("Sdk-User-Agent", app.config.sdkUserAgent)
}
// 请求类型
if app.httpContentType == "" {

@ -1,3 +1,3 @@
package gorequest
const Version = "1.0.43"
const Version = "1.0.44"

Loading…
Cancel
Save