Skip to content

Commit

Permalink
修复v1.1.17版本bug,支持python复用session
Browse files Browse the repository at this point in the history
  • Loading branch information
wangluozhe committed Sep 21, 2023
1 parent f55a194 commit 00431a8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# requests
[![Gitee link address](https://img.shields.io/badge/gitee-reference-red?logo=gitee&logoColor=red&labelColor=white)](https://gitee.com/leegene/requests)[![Github link address](https://img.shields.io/badge/github-reference-blue?logo=github&logoColor=black&labelColor=white&color=black)](https://github.com/wangluozhe/requests)[![Go Version](https://img.shields.io/badge/Go%20Version-1.20-blue?logo=go&logoColor=white&labelColor=gray)]()[![Release Version](https://img.shields.io/badge/release-v1.1.17-blue)]()[![go documentation](https://img.shields.io/badge/go-documentation-blue)](https://pkg.go.dev/github.com/wangluozhe/requests)[![license GPL-3.0](https://img.shields.io/badge/license-GPL3.0-orange)](https://github.com/wangluozhe/requests/blob/main/LICENSE)
[![Gitee link address](https://img.shields.io/badge/gitee-reference-red?logo=gitee&logoColor=red&labelColor=white)](https://gitee.com/leegene/requests)[![Github link address](https://img.shields.io/badge/github-reference-blue?logo=github&logoColor=black&labelColor=white&color=black)](https://github.com/wangluozhe/requests)[![Go Version](https://img.shields.io/badge/Go%20Version-1.20-blue?logo=go&logoColor=white&labelColor=gray)]()[![Release Version](https://img.shields.io/badge/release-v1.1.18-blue)]()[![go documentation](https://img.shields.io/badge/go-documentation-blue)](https://pkg.go.dev/github.com/wangluozhe/requests)[![license GPL-3.0](https://img.shields.io/badge/license-GPL3.0-orange)](https://github.com/wangluozhe/requests/blob/main/LICENSE)

requests支持以下新特性:

Expand Down
1 change: 1 addition & 0 deletions libs/types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package libs

type RequestParams struct {
Id string `json:"Id"`
Method string `json:"Method"`
Url string `json:"Url"`
Params map[string]string `json:"Params"`
Expand Down
12 changes: 11 additions & 1 deletion libs_dist/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ import (
var unsafePointers = make(map[string]*C.char)
var unsafePointersLock = sync.Mutex{}
var errorFormat = "{\"err\": \"%v\"}"
var session = make(map[string]*requests.Session)

func GetSession(id string) *requests.Session {
if ss, ok := session[id]; ok {
return ss
}
ss := requests.NewSession()
session[id] = ss
return ss
}

//export request
func request(requestParamsChar *C.char) *C.char {
Expand All @@ -37,7 +47,7 @@ func request(requestParamsChar *C.char) *C.char {
if c_err != nil {
return c_err
}
response, err := requests.Request(requestParams.Method, requestParams.Url, req)
response, err := GetSession(requestParams.Id).Request(requestParams.Method, requestParams.Url, req)
if err != nil {
return C.CString(fmt.Sprintf(errorFormat, err.Error()))
}
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package requests

const (
NAME = "golang-requests" // 名称
VERSION = "1.1.17" // 当前版本
VERSION = "1.1.18" // 当前版本
USER_AGENT = NAME + VERSION // UA
)

0 comments on commit 00431a8

Please sign in to comment.