目录
目录README.md

KCL Go SDK

GoDoc Coverage Status license

Building

$ 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

Testing

go test ./...

Run KCL Code with Go SDK

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

License

Apache License Version 2.0

关于

A constraint-based record & functional language mainly used in configuration and policy scenarios.

240.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

©Copyright 2023 CCF 开源发展委员会
Powered by Trustie& IntelliDE 京ICP备13000930号