- Install Go 17+
- Install kclvm (or
go run ./cmds/kcl-go/ setup-kclvm
and add./_build/{Darwin|Darwin-arm64|Linux}/bin
toPATH
)
$ go version
go version go1.17.8 darwin/arm64
$ which kclvm
$ kclvm -m kclvm --version
kclvm version is 0.4.1; checksum: ***
$ go test ./...
$ go run ./cmds/kcl-go
$ go run ./cmds/kcl-go run hello.k
package main
import (
"fmt"
"kusionstack.io/kclvm-go"
)
func main() {
yaml := kclvm.MustRun("hello.k", kclvm.WithCode(k_code)).First().YAMLString()
fmt.Println(yaml)
}
const k_code = `
import kcl_plugin.hello
name = "kcl"
age = 1
two = hello.add(1, 1)
schema Person:
name: str = "kcl"
age: int = 1
x0 = Person {}
x1 = Person {
age = 101
}
`
Output:
$ go run ./examples/hello/main.go
age: 1
name: kcl
two: 2
x0:
age: 1
name: kcl
x1:
age: 101
name: kcl
Apache License Version 2.0