修正函数返回值
This commit is contained in:
parent
627c05fd06
commit
ee7007f050
8
go.mod
8
go.mod
@ -46,9 +46,9 @@ require (
|
|||||||
github.com/ysmood/gson v0.7.3 // indirect
|
github.com/ysmood/gson v0.7.3 // indirect
|
||||||
github.com/ysmood/leakless v0.9.0 // indirect
|
github.com/ysmood/leakless v0.9.0 // indirect
|
||||||
github.com/yusufpapurcu/wmi v1.2.4 // indirect
|
github.com/yusufpapurcu/wmi v1.2.4 // indirect
|
||||||
golang.org/x/crypto v0.44.0 // indirect
|
golang.org/x/crypto v0.46.0 // indirect
|
||||||
golang.org/x/net v0.47.0 // indirect
|
golang.org/x/net v0.48.0 // indirect
|
||||||
golang.org/x/sys v0.38.0 // indirect
|
golang.org/x/sys v0.39.0 // indirect
|
||||||
golang.org/x/text v0.31.0 // indirect
|
golang.org/x/text v0.32.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
@ -93,7 +93,10 @@ func (r *Response) Write(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value
|
|||||||
args := gojs.MakeArgs(&argsIn, vm).Check(1)
|
args := gojs.MakeArgs(&argsIn, vm).Check(1)
|
||||||
n, err := r.resp.Write(args.Bytes(0))
|
n, err := r.resp.Write(args.Bytes(0))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(vm.NewGoError(err))
|
// panic(vm.NewGoError(err))
|
||||||
|
vm.SetData("_lastError", err)
|
||||||
|
gojs.GetLogger(vm).Error(err.Error())
|
||||||
|
return vm.ToValue(false)
|
||||||
}
|
}
|
||||||
return vm.ToValue(n)
|
return vm.ToValue(n)
|
||||||
}
|
}
|
||||||
|
|||||||
16
service.go
16
service.go
@ -260,7 +260,7 @@ func init() {
|
|||||||
// panic(vm.NewGoError(errors.New("server already started")))
|
// panic(vm.NewGoError(errors.New("server already started")))
|
||||||
vm.SetData("_lastError", errors.New("server already started"))
|
vm.SetData("_lastError", errors.New("server already started"))
|
||||||
gojs.GetLogger(vm).Error("server already started")
|
gojs.GetLogger(vm).Error("server already started")
|
||||||
return nil
|
return vm.ToValue(false)
|
||||||
}
|
}
|
||||||
// 处理静态文件
|
// 处理静态文件
|
||||||
if len(serviceConfig.Static) > 0 {
|
if len(serviceConfig.Static) > 0 {
|
||||||
@ -374,11 +374,11 @@ func init() {
|
|||||||
// panic(vm.NewGoError(errors.New("server not started")))
|
// panic(vm.NewGoError(errors.New("server not started")))
|
||||||
vm.SetData("_lastError", errors.New("server not started"))
|
vm.SetData("_lastError", errors.New("server not started"))
|
||||||
gojs.GetLogger(vm).Error("server not started")
|
gojs.GetLogger(vm).Error("server not started")
|
||||||
return nil
|
return vm.ToValue(false)
|
||||||
}
|
}
|
||||||
server.Stop()
|
server.Stop()
|
||||||
s.ResetAllSets()
|
s.ResetAllSets()
|
||||||
return nil
|
return vm.ToValue(true)
|
||||||
},
|
},
|
||||||
// "uniqueId": func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value {
|
// "uniqueId": func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value {
|
||||||
// args := gojs.MakeArgs(&argsIn, vm)
|
// args := gojs.MakeArgs(&argsIn, vm)
|
||||||
@ -495,7 +495,7 @@ func init() {
|
|||||||
// panic(vm.NewGoError(errors.New("action must be a callback function")))
|
// panic(vm.NewGoError(errors.New("action must be a callback function")))
|
||||||
vm.SetData("_lastError", errors.New("action must be a callback function"))
|
vm.SetData("_lastError", errors.New("action must be a callback function"))
|
||||||
gojs.GetLogger(vm).Error("action must be a callback function")
|
gojs.GetLogger(vm).Error("action must be a callback function")
|
||||||
return nil
|
return vm.ToValue(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
authLevel := o.Int("authLevel")
|
authLevel := o.Int("authLevel")
|
||||||
@ -589,7 +589,7 @@ func init() {
|
|||||||
// 无对象池,直接调用(单线程)
|
// 无对象池,直接调用(单线程)
|
||||||
s.RestfulWithOptions(authLevel, method, path, makeInnerAction(action, vm, args.This), memo, opt)
|
s.RestfulWithOptions(authLevel, method, path, makeInnerAction(action, vm, args.This), memo, opt)
|
||||||
}
|
}
|
||||||
return nil
|
return vm.ToValue(true)
|
||||||
},
|
},
|
||||||
"load": func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value {
|
"load": func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value {
|
||||||
args := gojs.MakeArgs(&argsIn, vm).Check(1)
|
args := gojs.MakeArgs(&argsIn, vm).Check(1)
|
||||||
@ -615,14 +615,14 @@ func init() {
|
|||||||
// panic(vm.NewGoError(errors.New("actionFile must be a js file path: " + fullActionFile)))
|
// panic(vm.NewGoError(errors.New("actionFile must be a js file path: " + fullActionFile)))
|
||||||
vm.SetData("_lastError", errors.New("actionFile must be a js file path: "+fullActionFile))
|
vm.SetData("_lastError", errors.New("actionFile must be a js file path: "+fullActionFile))
|
||||||
gojs.GetLogger(vm).Error("actionFile must be a js file path: " + fullActionFile)
|
gojs.GetLogger(vm).Error("actionFile must be a js file path: " + fullActionFile)
|
||||||
return nil
|
return vm.ToValue(false)
|
||||||
}
|
}
|
||||||
actionCode := u.ReadFileN(actionFile)
|
actionCode := u.ReadFileN(actionFile)
|
||||||
if !strings.Contains(actionCode, "function main(") { // || !strings.Contains(actionCode, ".register(")
|
if !strings.Contains(actionCode, "function main(") { // || !strings.Contains(actionCode, ".register(")
|
||||||
// panic(vm.NewGoError(errors.New("actionFile must be a js file with main function")))
|
// panic(vm.NewGoError(errors.New("actionFile must be a js file with main function")))
|
||||||
vm.SetData("_lastError", errors.New("actionFile must be a js file with main function"))
|
vm.SetData("_lastError", errors.New("actionFile must be a js file with main function"))
|
||||||
gojs.GetLogger(vm).Error("actionFile must be a js file with main function")
|
gojs.GetLogger(vm).Error("actionFile must be a js file with main function")
|
||||||
return nil
|
return vm.ToValue(false)
|
||||||
}
|
}
|
||||||
poolsLock.Lock()
|
poolsLock.Lock()
|
||||||
poolExists[actionFile] = true
|
poolExists[actionFile] = true
|
||||||
@ -646,7 +646,7 @@ func init() {
|
|||||||
poolsMTime[actionFile] = mtime
|
poolsMTime[actionFile] = mtime
|
||||||
poolsConfig[actionFile] = poolOpt
|
poolsConfig[actionFile] = poolOpt
|
||||||
poolsLock.Unlock()
|
poolsLock.Unlock()
|
||||||
return nil
|
return vm.ToValue(true)
|
||||||
},
|
},
|
||||||
// "task": func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value {
|
// "task": func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value {
|
||||||
// args := gojs.MakeArgs(&argsIn, vm).Check(1)
|
// args := gojs.MakeArgs(&argsIn, vm).Check(1)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user