- update version

master
dtapps 5 months ago
parent ad80d76806
commit df7b50a63a

@ -2,7 +2,7 @@
<a href="https://www.dtapp.net/">Golang</a> <a href="https://www.dtapp.net/">Golang</a>
</h1> </h1>
📦 Golang Request 📦 Golang 请求
[comment]: <> (go) [comment]: <> (go)
[![godoc](https://pkg.go.dev/badge/go.dtapp.net/gorequest?status.svg)](https://pkg.go.dev/go.dtapp.net/gorequest) [![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 ```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 package gorequest
import ( import (
"fmt"
"github.com/shirou/gopsutil/host" "github.com/shirou/gopsutil/host"
"log"
"runtime" "runtime"
) )
@ -13,26 +13,18 @@ type systemResult struct {
// 获取系统信息 // 获取系统信息
func getSystem() (result systemResult) { func getSystem() (result systemResult) {
hInfo, _ := host.Info()
hInfo, err := host.Info()
if err != nil {
log.Printf("getSystem.host.Info%s\n", err)
}
result.SystemOs = hInfo.OS result.SystemOs = hInfo.OS
result.SystemKernel = hInfo.KernelArch result.SystemKernel = hInfo.KernelArch
return result return result
} }
// 设置配置信息 // 设置配置信息
func (app *App) setConfig() { func (app *App) setConfig() {
info := getSystem() info := getSystem()
app.config.systemOs = info.SystemOs app.config.systemOs = info.SystemOs
app.config.systemKernel = info.SystemKernel app.config.systemKernel = info.SystemKernel
app.config.goVersion = runtime.Version() 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 package gorequest
const ( const (
userAgentFormat = "%s/%s/%s/%s" userAgentFormat1 = "%s/%s/%s"
userAgentFormat2 = "%s/%s/%s/%s"
) )
// 定义请求类型 // 定义请求类型

@ -56,6 +56,8 @@ type App struct {
systemOs string // 系统类型 systemOs string // 系统类型
systemKernel string // 系统内核 systemKernel string // 系统内核
goVersion string // go版本 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)) app.httpHeader.Set("Authorization", fmt.Sprintf("Bearer %s", token))
} }
// SetUserAgent 设置用户代理,空字符串就随机设置 // SetUserAgent 设置用户代理,空字符串就随机设置
func (app *App) SetUserAgent(ua string) { func (app *App) SetUserAgent(ua string) {
if ua == "" { if ua == "" {
ua = GetRandomUserAgent() ua = GetRandomUserAgent()
@ -115,6 +117,15 @@ func (app *App) SetUserAgent(ua string) {
app.httpHeader.Set("User-Agent", ua) 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格式 // SetContentTypeJson 设置JSON格式
func (app *App) SetContentTypeJson() { func (app *App) SetContentTypeJson() {
app.httpContentType = httpParamsModeJson app.httpContentType = httpParamsModeJson
@ -230,7 +241,9 @@ func request(app *App, ctx context.Context) (httpResponse Response, err error) {
} }
// SDK版本 // 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 == "" { if app.httpContentType == "" {

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

Loading…
Cancel
Save