3136352472
5 years ago
18 changed files with 2333 additions and 702 deletions
-
12govue/bindata.go
-
59govue/cmd/main.go
-
11govue/config.go
-
1286govue/govue-js-src/dist/index.js
-
1govue/govue-js-src/package.json
-
3govue/govue-js-src/predo.js
-
61govue/govue-js-src/src/goruntime.js
-
1286govue/govue-runtime/govue.js
-
66govue/govue-runtime/header.js
-
10govue/govue-runtime/runtime.js
-
39govue/govue.go
-
9jsruntime/cookie.go
-
152jsruntime/go_request.go
-
4jsruntime/runtime.go
-
4pool/pool.go
-
24static/404.html
-
3static/index.html
-
1static/use.js
12
govue/bindata.go
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
1286
govue/govue-js-src/dist/index.js
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
1286
govue/govue-runtime/govue.js
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,9 @@ |
|||
package jsruntime |
|||
|
|||
import "log" |
|||
|
|||
func (jr *JsRuntime) EnableCookieFun() { |
|||
jr.runtime.Set("setInterval", func() { |
|||
log.Println("禁用setInterval") |
|||
}) |
|||
} |
@ -1,50 +1,146 @@ |
|||
package jsruntime |
|||
|
|||
import ( |
|||
"bytes" |
|||
"encoding/json" |
|||
"git.ouxuan.net/hasaki-service/hasaki-sdk/hskhttpdo" |
|||
"github.com/parnurzeal/gorequest" |
|||
"fmt" |
|||
"io/ioutil" |
|||
"net/http" |
|||
"os" |
|||
"os/exec" |
|||
"path/filepath" |
|||
"strings" |
|||
"time" |
|||
) |
|||
|
|||
func (jr *JsRuntime) EnableRequestFunc() { |
|||
jr.runtime.Set("GoRequest", func(call map[string]interface{}) (statusCode int, respData string) { |
|||
jr.runtime.Set("GoRequest", func(call map[string]interface{}) (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"]
|
|||
url := "" |
|||
if call["url"] != nil { |
|||
url = call["url"].(string) |
|||
} |
|||
|
|||
data := "" |
|||
if call["data"] != nil { |
|||
data = call["data"].(string) |
|||
} |
|||
|
|||
header := map[string]interface{}{} |
|||
if call["header"] != nil { |
|||
header = call["header"].(map[string]interface{}) |
|||
} |
|||
|
|||
//log.Println("url.String()", url)
|
|||
//log.Println("data.String()", data)
|
|||
timeout := 0 |
|||
if call["timeout"] != nil { |
|||
switch call["timeout"].(type) { |
|||
case int64: |
|||
timeout = int(call["timeout"].(int64)) |
|||
case int: |
|||
timeout = call["timeout"].(int) |
|||
} |
|||
} |
|||
|
|||
client := &http.Client{} |
|||
method := "GET" |
|||
if call["method"] != nil { |
|||
method = call["method"].(string) |
|||
} |
|||
|
|||
req, err := http.NewRequest("GET", url, nil) |
|||
client := &http.Client{ |
|||
Timeout: time.Millisecond * time.Duration(timeout), |
|||
} |
|||
|
|||
var contentReader *bytes.Reader |
|||
contentReader = bytes.NewReader([]byte(data)) |
|||
|
|||
//log.Println(method, url, data)
|
|||
req, err := http.NewRequest(method, url, contentReader) |
|||
if err != nil { |
|||
rs, _ := json.Marshal(map[string]interface{}{ |
|||
"statusCode": 504, |
|||
"data": err.Error(), |
|||
}) |
|||
return string(rs) |
|||
} |
|||
|
|||
for e := range header { |
|||
req.Header.Add(e, header[e]) |
|||
req.Header.Set(e, header[e].(string)) |
|||
} |
|||
|
|||
resp, err := client.Do(req) |
|||
statusCode = resp.StatusCode |
|||
gorequest.New().Header. |
|||
|
|||
res, err := hskhttpdo.HttpDo{ |
|||
Url: url, |
|||
Raw: []byte(data), |
|||
}.Request(method) |
|||
var statusCode int |
|||
var respDatas string |
|||
|
|||
r := map[string]interface{}{ |
|||
"statusCode": 200, |
|||
"data": string(res), |
|||
} |
|||
if err != nil { |
|||
r["code"] = 502 |
|||
if err == nil { |
|||
defer resp.Body.Close() |
|||
statusCode = resp.StatusCode |
|||
rb, _ := ioutil.ReadAll(resp.Body) |
|||
respDatas = string(rb) |
|||
} else { |
|||
statusCode = 502 |
|||
respDatas = err.Error() |
|||
} |
|||
rs, _ := json.Marshal(r) |
|||
|
|||
log2File("netword", "-------------------------------------------------") |
|||
log2File("netword", "网络请求:", method, url) |
|||
headerStr, _ := json.Marshal(header) |
|||
log2File("netword", "网络请求头:", string(headerStr)) |
|||
log2File("netword", "网络请求发送数据:", data) |
|||
log2File("netword", "请求返回状态:", err == nil) |
|||
log2File("netword", "请求返回状态码:", statusCode) |
|||
log2File("netword", "请求返回:", respDatas) |
|||
log2File("netword", "-------------------------------------------------") |
|||
|
|||
rs, _ := json.Marshal(map[string]interface{}{ |
|||
"statusCode": statusCode, |
|||
"data": string(respDatas), |
|||
}) |
|||
return string(rs) |
|||
}) |
|||
} |
|||
|
|||
func log2File(tag string, strs ...interface{}) { |
|||
str := fmt.Sprintln(strs...) |
|||
path := filepath.Join(getSelfFilePath(), fmt.Sprintf("jsruntime-%s.log", tag)) |
|||
if pathExists(path) { |
|||
raw, _ := ioutil.ReadFile(path) |
|||
str = string(raw) + str |
|||
} |
|||
ioutil.WriteFile(path, []byte(str), 0644) |
|||
} |
|||
|
|||
func pathExists(path string) bool { |
|||
_, err := os.Stat(path) |
|||
if err == nil { |
|||
return true |
|||
} |
|||
if os.IsNotExist(err) { |
|||
return false |
|||
} |
|||
return false |
|||
} |
|||
|
|||
var selfFilePath string |
|||
|
|||
func getSelfFilePath() string { |
|||
if selfFilePath == "" { |
|||
file, err := exec.LookPath(os.Args[0]) |
|||
if err != nil { |
|||
return "" |
|||
} |
|||
path, err := filepath.Abs(file) |
|||
if err != nil { |
|||
return "" |
|||
} |
|||
i := strings.LastIndex(path, "/") |
|||
if i < 0 { |
|||
i = strings.LastIndex(path, "\\") |
|||
} |
|||
if i < 0 { |
|||
return "" |
|||
} |
|||
selfFilePath, _ = filepath.Abs(string(path[0 : i+1])) |
|||
} |
|||
return selfFilePath |
|||
} |
@ -0,0 +1,24 @@ |
|||
<!doctype html> |
|||
<html lang="zh"> |
|||
<head> |
|||
<meta charset="utf-8"> |
|||
<meta name="keywords" content=""> |
|||
<link rel="stylesheet" href="css/main.css"> |
|||
<script src="js/vue.min.js"></script> |
|||
</head> |
|||
|
|||
<body> |
|||
<div id="app" class="content"> |
|||
<my-title></my-title> |
|||
<a>404 找不到页面 {{desc}}</a> |
|||
</div> |
|||
</body> |
|||
<script gv-src> |
|||
new Vue({ |
|||
el: "#app", |
|||
data: { |
|||
"desc": "基础golang开发的一套vue服务端渲染方案" |
|||
}, |
|||
}); |
|||
</script> |
|||
</html> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue