Categorygithub.com/alextanhongpin/go-embed
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?

For javascript, there's vm and vm2, and isolated-vm that is used by temporal.

Another language that is similar to go is vlang.

https://dhall-lang.org

References

  1. https://otm.github.io/2015/07/embedding-lua-in-go/
  2. 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!"
	     }
	   }
	*/
}

# Packages

This can be used as the basics for rule engine.
References: https://github.com/antonmedv/expr/blob/master/docs/Visitor-and-Patch.md.
No description provided by the author
No description provided by the author