Go to file
2024-11-13 17:04:32 +08:00
base64dec change dir for goja 2024-10-10 17:08:01 +08:00
goja change dir for goja 2024-10-10 17:08:01 +08:00
goja_nodejs change dir for goja 2024-10-10 17:08:01 +08:00
makeGoja change dir for goja 2024-10-10 17:08:01 +08:00
.gitignore first 2024-10-10 16:44:10 +08:00
args.go support bridge and makeTS 2024-11-13 17:04:32 +08:00
bridge.go support bridge and makeTS 2024-11-13 17:04:32 +08:00
common.go change dir for goja 2024-10-10 17:08:01 +08:00
go.mod support bridge and makeTS 2024-11-13 17:04:32 +08:00
gojs_test.go change dir for goja 2024-10-10 17:08:01 +08:00
gojs.go add __startExec、__runFile 2024-10-26 22:11:41 +08:00
lb.go first 2024-10-10 16:44:10 +08:00
LICENSE first 2024-10-10 16:44:10 +08:00
makeTS.go support bridge and makeTS 2024-11-13 17:04:32 +08:00
pool.go first 2024-10-10 16:44:10 +08:00
README.md first 2024-10-10 16:44:10 +08:00

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])
}