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.
 
 

50 lines
1.1 KiB

package jsruntime
import (
"encoding/json"
"git.ouxuan.net/hasaki-service/hasaki-sdk/hskhttpdo"
"github.com/parnurzeal/gorequest"
"net/http"
)
func (jr *JsRuntime) EnableRequestFunc() {
jr.runtime.Set("GoRequest", func(call map[string]interface{}) (statusCode int, respData string) {
url := call["url"].(string)
data := call["data"]
header := call["header"].(map[string]string)
//timeout := call.Argument(3)
method := call["method"].(string)
//dataType := call["dataType"]
//responseType := call["responseType"]
//log.Println("url.String()", url)
//log.Println("data.String()", data)
client := &http.Client{}
req, err := http.NewRequest("GET", url, nil)
for e := range header {
req.Header.Add(e, header[e])
}
resp, err := client.Do(req)
statusCode = resp.StatusCode
gorequest.New().Header.
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)
})
}