base64dec | ||
goja | ||
goja_nodejs | ||
makeGoja | ||
.gitignore | ||
args.go | ||
bridge.go | ||
common.go | ||
go.mod | ||
gojs_test.go | ||
gojs.go | ||
lb.go | ||
LICENSE | ||
makeTS.go | ||
pool.go | ||
README.md |
GoJS
The project is a low-code framework implemented in Go, with a low-code language written in JavaScript. The framework allows developers to create modules in Go that can be called from the JavaScript code. The entire project can be compiled into a standalone executable file, making it easy to deploy and use.
create a module
package apigo.cc/yourorg/modulename
import "apigo.cc/gojs"
func init() {
defaultObject := Object{id: "o-00"}
gojs.Register("apigo.cc/yourorg/modulename", gojs.Module{
Object: map[string]any{
"name": "abc",
"plus": func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value {
args := gojs.MakeArgs(&argsIn, vm).Check(2)
return vm.ToValue(args.Int(0) + args.Int(1))
},
"getName": func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value {
args := gojs.MakeArgs(&argsIn, vm)
this := args.ThisObj()
return vm.ToValue(this.Str("name"))
},
},
})
}
usage for inline js code
package main
import (
"fmt"
"apigo.cc/gojs"
_ "apigo.cc/yourorg/modulename"
)
func main() {
r, err := gojs.Run(`
import mod from 'apigo.cc/yourorg/modulename'
function main(args){
return mod.getName()
}
`, "test.js")
fmt.Println(r, err, r == "abc")
}
usage for separate js file
main.go
package main
import (
"fmt"
"apigo.cc/gojs"
_ "apigo.cc/yourorg/modulename"
)
func main() {
r, err := gojs.RunFile("plus.js", 1, 2)
fmt.Println(r, err, r == 3)
}
plus.js
import mod from 'apigo.cc/yourorg/modulename'
function main(args){
return mod.plus(args[0], args[1])
}