modulepackage
0.0.0-20241028060125-899b06f7d1e8
Repository: https://github.com/alextanhongpin/go-embed.git
Documentation: pkg.go.dev
# README
go-embed
Why embed another language in golang?
- WIP
What other language do we have?
- expr
- python
- two lib for lua, gopher-lua and go-lua
- otto allows ES5 JavaScript only, see v8g0
- v8go, probably can be used to emulate Cloudflare Workers (which are most likely using containers)
- cuego as well as cuelang
- tengo
- go+ a language for engineering, STEM education, and data science
- jsonnet
- starlark, and starlark-go
- cel-go
- go-bexpr from Hashicorp
- jsonata
- https://www.kcl-lang.io/docs/user_docs/getting-started/kcl-quick-start
For javascript, there's vm and vm2, and isolated-vm that is used by temporal.
Another language that is similar to go is vlang.
References
- https://otm.github.io/2015/07/embedding-lua-in-go/
- https://go.libhunt.com/categories/485-embeddable-scripting-languages
go-jsonnet
An alternative to modify json dynamically in golang since jsonata port doesn't exist.
package main
import (
"fmt"
"log"
"github.com/google/go-jsonnet"
)
func main() {
vm := jsonnet.MakeVM()
snippet := `{
person1: {
name: "Alice",
welcome: "Hello " + std.extVar("name").name + "!",
},
person2: self.person1 { name: "Bob" },
}`
// vm.ExtVar("sth", "else") // This is only string
vm.ExtCode("name", `{"name": "john"}`) // Object is allowed
jsonStr, err := vm.EvaluateAnonymousSnippet("example1.jsonnet", snippet)
if err != nil {
log.Fatal(err)
}
fmt.Println(jsonStr)
/*
{
"person1": {
"name": "Alice",
"welcome": "Hello Alice!"
},
"person2": {
"name": "Bob",
"welcome": "Hello Bob!"
}
}
*/
}