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
|
- name: Checkout V8Go
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
repository: rogchap/v8go
|
repository: yaoapp/v8go
|
||||||
# ref: aac4923ed74083e58ae7b42b1acb0fa0d11a26cb
|
lfs: true
|
||||||
path: v8go
|
path: v8go
|
||||||
|
|
||||||
- name: Checkout XGen v1.0
|
- 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
|
- name: Checkout V8Go
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
repository: rogchap/v8go
|
repository: yaoapp/v8go
|
||||||
# ref: aac4923ed74083e58ae7b42b1acb0fa0d11a26cb
|
lfs: true
|
||||||
path: v8go
|
path: v8go
|
||||||
|
|
||||||
- name: Checkout XGen v1.0
|
- 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
|
- name: Checkout V8Go
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
repository: rogchap/v8go
|
repository: yaoapp/v8go
|
||||||
# ref: aac4923ed74083e58ae7b42b1acb0fa0d11a26cb
|
lfs: true
|
||||||
path: v8go
|
path: v8go
|
||||||
|
|
||||||
- name: Checkout Demo App
|
- 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
|
- name: Checkout V8Go
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
repository: rogchap/v8go
|
repository: yaoapp/v8go
|
||||||
# ref: aac4923ed74083e58ae7b42b1acb0fa0d11a26cb
|
lfs: true
|
||||||
path: v8go
|
path: v8go
|
||||||
|
|
||||||
- name: Checkout Demo App
|
- name: Checkout Demo App
|
||||||
|
|
|
||||||
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -11,6 +11,8 @@
|
||||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||||
*.out
|
*.out
|
||||||
|
|
||||||
|
*.log
|
||||||
|
|
||||||
# Dependency directories (remove the comment below to include it)
|
# Dependency directories (remove the comment below to include it)
|
||||||
# vendor/
|
# vendor/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ type Session struct {
|
||||||
|
|
||||||
// Runtime Config
|
// Runtime Config
|
||||||
type Runtime struct {
|
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
|
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
|
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
|
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()
|
defer v8ctx.Close()
|
||||||
|
|
||||||
// make a new bridge function ssWrite
|
v8ctx.WithFunction("ssWrite", func(info *v8go.FunctionCallbackInfo) *v8go.Value {
|
||||||
ssWriteT := v8go.NewFunctionTemplate(v8ctx.Isolate(), func(info *v8go.FunctionCallbackInfo) *v8go.Value {
|
|
||||||
args := info.Args()
|
args := info.Args()
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
return v8go.Null(v8ctx.Isolate())
|
return v8go.Null(info.Context().Isolate())
|
||||||
}
|
}
|
||||||
|
|
||||||
text := args[0].String()
|
text := args[0].String()
|
||||||
cb(req.msg().Text(text))
|
cb(req.msg().Text(text))
|
||||||
return v8go.Null(v8ctx.Isolate())
|
return v8go.Null(info.Context().Isolate())
|
||||||
})
|
})
|
||||||
|
|
||||||
// make a new bridge function done
|
v8ctx.WithFunction("done", func(info *v8go.FunctionCallbackInfo) *v8go.Value {
|
||||||
doneT := v8go.NewFunctionTemplate(v8ctx.Isolate(), func(info *v8go.FunctionCallbackInfo) *v8go.Value {
|
|
||||||
args := info.Args()
|
args := info.Args()
|
||||||
if len(args) == 1 {
|
if len(args) == 1 {
|
||||||
text := args[0].String()
|
text := args[0].String()
|
||||||
|
|
@ -398,12 +396,9 @@ func (req *Request) runScript(id string, args []interface{}, cb func(msg *messag
|
||||||
|
|
||||||
cb(req.msg().Done())
|
cb(req.msg().Done())
|
||||||
// req.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...)
|
res, err := v8ctx.CallWith(req.ctx, method, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,12 @@ func (r *Request) Render() (string, int, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save to The Cache
|
// 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)
|
log.Trace("The page %s is cached", r.File)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue