Merge pull request ‘feat: generate kcl from json, yaml and terraform’ (#2) from p4mp8ftwn/KCLVM:feat/import into master
$ go run ./cmds/kcl-go $ go run ./cmds/kcl-go run hello.k name: kcl age: 1 two: 2 x0: name: kcl age: 1 x1: name: kcl age: 101
go test ./...
package main import ( "fmt" kcl "kcl-lang.io/kcl-go" ) func main() { yaml := kcl.MustRun("kubernetes.k", kcl.WithCode(k_code)).GetRawYamlResult() fmt.Println(yaml) } const k_code = ` apiVersion = "apps/v1" kind = "Deployment" metadata = { name = "nginx" labels.app = "nginx" } spec = { replicas = 3 selector.matchLabels = metadata.labels template.metadata.labels = metadata.labels template.spec.containers = [ { name = metadata.name image = "${metadata.name}:1.14.2" ports = [{ containerPort = 80 }] } ] } `
Run the command:
go run ./examples/kubernetes/main.go
Output:
apiVersion: apps/v1 kind: Deployment metadata: name: nginx labels: app: nginx spec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.14.2 ports: - containerPort: 80
Apache License Version 2.0
A constraint-based record & functional language mainly used in configuration and policy scenarios.
©Copyright 2023 CCF 开源发展委员会 Powered by Trustie& IntelliDE 京ICP备13000930号
KCL Go SDK
Building
Testing
Run KCL Code with Go SDK
Run the command:
Output:
License
Apache License Version 2.0