+ 升级Gou & Script 功能升级
This commit is contained in:
parent
6d6b807e5a
commit
9e658974d9
7 changed files with 43 additions and 10 deletions
3
go.mod
3
go.mod
|
|
@ -14,8 +14,6 @@ require (
|
|||
github.com/gin-gonic/gin v1.7.4
|
||||
github.com/go-sql-driver/mysql v1.6.0 // indirect
|
||||
github.com/golang-jwt/jwt v3.2.2+incompatible
|
||||
github.com/hashicorp/go-hclog v1.0.0 // indirect
|
||||
github.com/hashicorp/go-plugin v1.4.3 // indirect
|
||||
github.com/hashicorp/yamux v0.0.0-20210826001029-26ff87cf9493 // indirect
|
||||
github.com/jmoiron/sqlx v1.3.4 // indirect
|
||||
github.com/joho/godotenv v1.3.0
|
||||
|
|
@ -23,7 +21,6 @@ require (
|
|||
github.com/lib/pq v1.10.3 // indirect
|
||||
github.com/mattn/go-sqlite3 v1.14.8 // indirect
|
||||
github.com/mojocn/base64Captcha v1.3.5
|
||||
github.com/robertkrimen/otto v0.0.0-20211004134430-12a632260352 // indirect
|
||||
github.com/satori/go.uuid v1.2.0 // indirect
|
||||
github.com/spf13/afero v1.6.0
|
||||
github.com/spf13/cobra v1.2.1
|
||||
|
|
|
|||
10
go.sum
10
go.sum
|
|
@ -320,9 +320,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
|
|||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
|
||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/robertkrimen/otto v0.0.0-20210614181706-373ff5438452/go.mod h1:xvqspoSXJTIpemEonrMDFq6XzwHYYgToXWj5eRX1OtY=
|
||||
github.com/robertkrimen/otto v0.0.0-20211004134430-12a632260352 h1:hqx3srlCjXphJgUFQqfo41HrWvZuYvMM9WEkb3oBgi0=
|
||||
github.com/robertkrimen/otto v0.0.0-20211004134430-12a632260352/go.mod h1:/mK7FZ3mFYEn9zvNPhpngTyatyehSwte5bJZ4ehL5Xw=
|
||||
github.com/robertkrimen/otto v0.0.0-20211024170158-b87d35c0b86f h1:a7clxaGmmqtdNTXyvrp/lVO/Gnkzlhc/+dLs5v965GM=
|
||||
github.com/robertkrimen/otto v0.0.0-20211024170158-b87d35c0b86f/go.mod h1:/mK7FZ3mFYEn9zvNPhpngTyatyehSwte5bJZ4ehL5Xw=
|
||||
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
|
||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
|
||||
|
|
@ -391,7 +390,6 @@ golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8U
|
|||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 h1:7I4JAnoQBe7ZtJcBaYHi5UtiO8tQHbUSXxL+pnGRANg=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
|
|
@ -548,8 +546,8 @@ golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBc
|
|||
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211004093028-2c5d950f24ef/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211006225509-1a26e0398eed h1:E159xujlywdAeN3FqsTBPzRKGUq/pDHolXbuttkC36E=
|
||||
golang.org/x/sys v0.0.0-20211006225509-1a26e0398eed/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211105183446-c75c47738b0c h1:+8miTPjMCTXwih7BQmvWwd0PjdBZq2MKp/qQaahSzEM=
|
||||
golang.org/x/sys v0.0.0-20211105183446-c75c47738b0c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import (
|
|||
)
|
||||
|
||||
// VERSION 版本号
|
||||
const VERSION = "0.9.1"
|
||||
const VERSION = "0.9.2"
|
||||
|
||||
// DOMAIN 许可域
|
||||
const DOMAIN = "*.iqka.com"
|
||||
|
|
|
|||
|
|
@ -4,10 +4,12 @@ import (
|
|||
"fmt"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/gou/query/share"
|
||||
"github.com/yaoapp/kun/exception"
|
||||
"github.com/yaoapp/kun/maps"
|
||||
"github.com/yaoapp/xiang/config"
|
||||
"github.com/yaoapp/xiang/xlog"
|
||||
)
|
||||
|
||||
// Libs 共享库
|
||||
|
|
@ -24,6 +26,8 @@ func LoadFrom(dir string) {
|
|||
if DirNotExists(dir) {
|
||||
return
|
||||
}
|
||||
|
||||
// 加载共享数据
|
||||
Walk(dir, ".json", func(root, filename string) {
|
||||
name := SpecName(root, filename)
|
||||
content := ReadFile(filename)
|
||||
|
|
@ -41,6 +45,15 @@ func LoadFrom(dir string) {
|
|||
}
|
||||
}
|
||||
})
|
||||
|
||||
// 加载共享脚本
|
||||
Walk(dir, ".js", func(root, filename string) {
|
||||
name := SpecName(root, filename)
|
||||
err := gou.JavaScriptVM.Load(filename, name)
|
||||
if err != nil {
|
||||
xlog.Printf("加载脚本失败 %s", err.Error())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// UnmarshalJSON Column 字段JSON解析
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/xiang/config"
|
||||
)
|
||||
|
||||
|
|
@ -63,3 +64,9 @@ func TestAPI(t *testing.T) {
|
|||
jsoniter.Unmarshal([]byte(content), &api)
|
||||
assert.Equal(t, []interface{}{nil, nil, float64(10)}, api.Default)
|
||||
}
|
||||
|
||||
func TestScript(t *testing.T) {
|
||||
res, err := gou.JavaScriptVM.Run("time", "hello", "world")
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "name:world", res)
|
||||
}
|
||||
|
|
|
|||
13
tests/libs/time.js
Normal file
13
tests/libs/time.js
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
function now() {
|
||||
return new Date().toISOString().split("T")[0];
|
||||
}
|
||||
|
||||
function lastYear() {
|
||||
var d = new Date();
|
||||
d.setFullYear(d.getFullYear() - 1);
|
||||
return d.toISOString().split("T")[0];
|
||||
}
|
||||
|
||||
function hello(name) {
|
||||
return "name:" + name;
|
||||
}
|
||||
5
tests/libs/tree.js
Normal file
5
tests/libs/tree.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
function main(args, out, res) {
|
||||
return {
|
||||
tree: {},
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue