Skip to content

Commit

Permalink
+ network.put & fix header bug
Browse files Browse the repository at this point in the history
  • Loading branch information
trheyi committed Jan 7, 2022
1 parent 10bf413 commit a8e9a55
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 35 deletions.
54 changes: 27 additions & 27 deletions data/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions network/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ func init() {
gou.RegisterProcessHandler("xiang.network.Get", ProcessGet)
gou.RegisterProcessHandler("xiang.network.Post", ProcessPost)
gou.RegisterProcessHandler("xiang.network.PostJSON", ProcessPostJSON)
gou.RegisterProcessHandler("xiang.network.Put", ProcessPut)
gou.RegisterProcessHandler("xiang.network.PutJSON", ProcessPutJSON)
gou.RegisterProcessHandler("xiang.network.Send", ProcessSend)
}
14 changes: 14 additions & 0 deletions network/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ func RequestPostJSON(url string, data interface{}, headers map[string]string) Re
return RequestSend("POST", url, map[string]interface{}{}, data, headers)
}

// RequestPut 发送PUT请求
func RequestPut(url string, data interface{}, headers map[string]string) Response {
return RequestSend("PUT", url, map[string]interface{}{}, data, headers)
}

// RequestPutJSON 发送PUT请求
func RequestPutJSON(url string, data interface{}, headers map[string]string) Response {
if headers == nil {
headers = map[string]string{}
}
headers["content-type"] = "application/json;charset=utf8"
return RequestSend("POST", url, map[string]interface{}{}, data, headers)
}

// RequestSend 发送Request请求
func RequestSend(method string, url string, params map[string]interface{}, data interface{}, headers map[string]string) Response {

Expand Down
50 changes: 43 additions & 7 deletions network/request.process.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import (
func ProcessPost(process *gou.Process) interface{} {
process.ValidateArgNums(1)
var data interface{}
var headers map[string]string

var headers = map[string]string{}
url := process.ArgsString(0)
if process.NumOfArgs() > 1 {
data = process.Args[1]
Expand All @@ -29,7 +28,7 @@ func ProcessPost(process *gou.Process) interface{} {
func ProcessPostJSON(process *gou.Process) interface{} {
process.ValidateArgNums(1)
var data interface{}
headers := map[string]string{}
var headers = map[string]string{}
url := process.ArgsString(0)
if process.NumOfArgs() > 1 {
data = process.Args[1]
Expand All @@ -43,12 +42,48 @@ func ProcessPostJSON(process *gou.Process) interface{} {
return RequestPostJSON(url, data, headers)
}

// ProcessPut xiang.helper.Put HTTP PUT
func ProcessPut(process *gou.Process) interface{} {
process.ValidateArgNums(1)
var data interface{}
var headers = map[string]string{}
url := process.ArgsString(0)
if process.NumOfArgs() > 1 {
data = process.Args[1]
}
if process.NumOfArgs() > 2 {
inputHeaders := process.ArgsMap(2)
for name, value := range inputHeaders {
headers[name] = fmt.Sprintf("%v", value)
}
}
return RequestPut(url, data, headers)
}

// ProcessPutJSON xiang.helper.PutJSON HTTP PUT
func ProcessPutJSON(process *gou.Process) interface{} {
process.ValidateArgNums(1)
var data interface{}
var headers = map[string]string{}
url := process.ArgsString(0)
if process.NumOfArgs() > 1 {
data = process.Args[1]
}
if process.NumOfArgs() > 2 {
inputHeaders := process.ArgsMap(2)
for name, value := range inputHeaders {
headers[name] = fmt.Sprintf("%v", value)
}
}
return RequestPutJSON(url, data, headers)
}

// ProcessSend xiang.helper.Send HTTP Send
func ProcessSend(process *gou.Process) interface{} {
process.ValidateArgNums(2)
var params map[string]interface{}
var data interface{}
var headers map[string]string
var params = map[string]interface{}{}
var headers = map[string]string{}
method := process.ArgsString(0)
url := process.ArgsString(1)
if process.NumOfArgs() > 2 {
Expand All @@ -71,8 +106,8 @@ func ProcessSend(process *gou.Process) interface{} {
// ProcessGet xiang.helper.Get HTTP Get
func ProcessGet(process *gou.Process) interface{} {
process.ValidateArgNums(1)
var params map[string]interface{}
var headers map[string]string
var params = map[string]interface{}{}
var headers = map[string]string{}
url := process.ArgsString(0)
if process.NumOfArgs() > 1 {
params = process.ArgsMap(1)
Expand All @@ -83,5 +118,6 @@ func ProcessGet(process *gou.Process) interface{} {
headers[name] = fmt.Sprintf("%v", value)
}
}

return RequestGet(url, params, headers)
}
2 changes: 1 addition & 1 deletion share/const.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package share

// VERSION 版本号
const VERSION = "0.9.22"
const VERSION = "0.9.23"

// DOMAIN 许可域(废弃)
const DOMAIN = "*.iqka.com"
Expand Down

0 comments on commit a8e9a55

Please sign in to comment.