Merge pull request #538 from trheyi/main
[add] Refactor bridge functions in request.go
This commit is contained in:
commit
ea67412b98
8 changed files with 23 additions and 21 deletions
4
.github/workflows/build-linux.yml
vendored
4
.github/workflows/build-linux.yml
vendored
|
|
@ -75,8 +75,8 @@ jobs:
|
|||
- name: Checkout V8Go
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
repository: rogchap/v8go
|
||||
# ref: aac4923ed74083e58ae7b42b1acb0fa0d11a26cb
|
||||
repository: yaoapp/v8go
|
||||
lfs: true
|
||||
path: v8go
|
||||
|
||||
- name: Checkout XGen v1.0
|
||||
|
|
|
|||
4
.github/workflows/build-macos.yml
vendored
4
.github/workflows/build-macos.yml
vendored
|
|
@ -56,8 +56,8 @@ jobs:
|
|||
- name: Checkout V8Go
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
repository: rogchap/v8go
|
||||
# ref: aac4923ed74083e58ae7b42b1acb0fa0d11a26cb
|
||||
repository: yaoapp/v8go
|
||||
lfs: true
|
||||
path: v8go
|
||||
|
||||
- name: Checkout XGen v1.0
|
||||
|
|
|
|||
4
.github/workflows/pr-test.yml
vendored
4
.github/workflows/pr-test.yml
vendored
|
|
@ -150,8 +150,8 @@ jobs:
|
|||
- name: Checkout V8Go
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
repository: rogchap/v8go
|
||||
# ref: aac4923ed74083e58ae7b42b1acb0fa0d11a26cb
|
||||
repository: yaoapp/v8go
|
||||
lfs: true
|
||||
path: v8go
|
||||
|
||||
- name: Checkout Demo App
|
||||
|
|
|
|||
4
.github/workflows/unit-test.yml
vendored
4
.github/workflows/unit-test.yml
vendored
|
|
@ -107,8 +107,8 @@ jobs:
|
|||
- name: Checkout V8Go
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
repository: rogchap/v8go
|
||||
# ref: aac4923ed74083e58ae7b42b1acb0fa0d11a26cb
|
||||
repository: yaoapp/v8go
|
||||
lfs: true
|
||||
path: v8go
|
||||
|
||||
- name: Checkout Demo App
|
||||
|
|
|
|||
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -11,6 +11,8 @@
|
|||
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||
*.out
|
||||
|
||||
*.log
|
||||
|
||||
# Dependency directories (remove the comment below to include it)
|
||||
# vendor/
|
||||
.DS_Store
|
||||
|
|
@ -35,4 +37,4 @@ xgen/v1.0/*
|
|||
!xgen/v1.0/index.html
|
||||
!xgen/v1.0/umi.js
|
||||
!xgen/v1.0/layouts__index.async.js
|
||||
*-unit-test
|
||||
*-unit-test
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ type Session struct {
|
|||
|
||||
// Runtime Config
|
||||
type Runtime struct {
|
||||
Mode string `json:"mode,omitempty" env:"YAO_RUNTIME_MODE" envDefault:"normal"` // the mode of the runtime, the default value is "normal" and the other value is "performance". "performance" mode need more memory but will run faster
|
||||
Mode string `json:"mode,omitempty" env:"YAO_RUNTIME_MODE" envDefault:"standard"` // the mode of the runtime, the default value is "standard" and the other value is "performance". "performance" mode need more memory but will run faster
|
||||
MinSize int `json:"minSize,omitempty" env:"YAO_RUNTIME_MIN" envDefault:"10"` // the number of V8 VM when runtime start. max value is 100, the default value is 2
|
||||
MaxSize int `json:"maxSize,omitempty" env:"YAO_RUNTIME_MAX" envDefault:"100"` // the maximum of V8 VM should be smaller than minSize, the default value is 10
|
||||
DefaultTimeout int `json:"defaultTimeout,omitempty" env:"YAO_RUNTIME_TIMEOUT" envDefault:"200"` // the default timeout for the script, the default value is 200ms
|
||||
|
|
|
|||
|
|
@ -376,20 +376,18 @@ func (req *Request) runScript(id string, args []interface{}, cb func(msg *messag
|
|||
}
|
||||
defer v8ctx.Close()
|
||||
|
||||
// make a new bridge function ssWrite
|
||||
ssWriteT := v8go.NewFunctionTemplate(v8ctx.Isolate(), func(info *v8go.FunctionCallbackInfo) *v8go.Value {
|
||||
v8ctx.WithFunction("ssWrite", func(info *v8go.FunctionCallbackInfo) *v8go.Value {
|
||||
args := info.Args()
|
||||
if len(args) != 1 {
|
||||
return v8go.Null(v8ctx.Isolate())
|
||||
return v8go.Null(info.Context().Isolate())
|
||||
}
|
||||
|
||||
text := args[0].String()
|
||||
cb(req.msg().Text(text))
|
||||
return v8go.Null(v8ctx.Isolate())
|
||||
return v8go.Null(info.Context().Isolate())
|
||||
})
|
||||
|
||||
// make a new bridge function done
|
||||
doneT := v8go.NewFunctionTemplate(v8ctx.Isolate(), func(info *v8go.FunctionCallbackInfo) *v8go.Value {
|
||||
v8ctx.WithFunction("done", func(info *v8go.FunctionCallbackInfo) *v8go.Value {
|
||||
args := info.Args()
|
||||
if len(args) == 1 {
|
||||
text := args[0].String()
|
||||
|
|
@ -398,12 +396,9 @@ func (req *Request) runScript(id string, args []interface{}, cb func(msg *messag
|
|||
|
||||
cb(req.msg().Done())
|
||||
// req.Done()
|
||||
return v8go.Null(v8ctx.Isolate())
|
||||
return v8go.Null(v8ctx.Context.Isolate())
|
||||
})
|
||||
|
||||
v8ctx.Global().Set("ssWrite", ssWriteT.GetFunction(v8ctx.Context))
|
||||
v8ctx.Global().Set("done", doneT.GetFunction(v8ctx.Context))
|
||||
|
||||
res, err := v8ctx.CallWith(req.ctx, method, args...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
|
|
@ -102,7 +102,12 @@ func (r *Request) Render() (string, int, error) {
|
|||
}
|
||||
|
||||
// Save to The Cache
|
||||
c = core.SetCache(r.File, html, dataText, globalDataText)
|
||||
// c = core.SetCache(r.File, html, dataText, globalDataText)
|
||||
c = &core.Cache{
|
||||
Data: dataText,
|
||||
Global: globalDataText,
|
||||
HTML: html,
|
||||
}
|
||||
log.Trace("The page %s is cached", r.File)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue