You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
768 B
37 lines
768 B
package jsruntime
|
|
|
|
import (
|
|
"encoding/json"
|
|
"git.ouxuan.net/hasaki-service/hasaki-sdk/hskhttpdo"
|
|
)
|
|
|
|
func (jr *JsRuntime) EnableRequestFunc() {
|
|
jr.runtime.Set("GoRequest", func(call map[string]string) string {
|
|
|
|
url := call["url"]
|
|
data := call["data"]
|
|
//header := call.Argument(2)
|
|
//timeout := call.Argument(3)
|
|
method := call["method"]
|
|
//dataType := call["dataType"]
|
|
//responseType := call["responseType"]
|
|
|
|
//log.Println("url.String()", url)
|
|
//log.Println("data.String()", data)
|
|
|
|
res, err := hskhttpdo.HttpDo{
|
|
Url: url,
|
|
Raw: []byte(data),
|
|
}.Request(method)
|
|
|
|
r := map[string]interface{}{
|
|
"statusCode": 200,
|
|
"data": string(res),
|
|
}
|
|
if err != nil {
|
|
r["code"] = 502
|
|
}
|
|
rs, _ := json.Marshal(r)
|
|
return string(rs)
|
|
})
|
|
}
|