Go Implementation
The Go implementation is available at https://github.com/hoplang/hop-go.
Quickstart
To install the dependency, run the command:
sh
go get github.com/hoplang/hop-go
Then add the import to your package:
go
package main
import (
"github.com/hoplang/hop-go"
)
Then instantiate a compiler, add the modules and compile them to obtain a hop program.
go
compiler := hop.NewCompiler()
compiler.AddFS(fs)
program, err := compiler.Compile()
Using the program you can now execute hop functions from any hop module.
go
var buf bytes.Buffer
err := program.ExecuteFunction(
&buf,
"my-module",
"my-function",
data,
)
Data modeling
In hop, Go slices corresponds to arrays and maps and structs corresponds to objects.
That is, given the following function:
html
<function name="my-function" params-as="params">
<div inner-text="params.foo"></div>
</function>
Both of these definitions for data
are valid:
go
data := map[string]string{
{"foo": "bar"}
}
go
type Data struct {
Foo string `json:"foo"`
}
data := Data{Foo: "bar"}