go-api
kclvm
import "github.com/kcl-lang/kcl-go"
KCL Go SDK
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ kcl files │ │ KCL-Go-API │ │ KCLResultList │
│ ┌───────────┐ │ │ │ │ │
│ │ 1.k │ │ │ │ │ │
│ └───────────┘ │ │ │ │ ┌───────────┐ │ ┌───────────────┐
│ ┌───────────┐ │ │ ┌───────────┐ │ │ │ KCLResult │──┼────────▶│x.Get("a.b.c") │
│ │ 2.k │ │ │ │ Run(path) │ │ │ └───────────┘ │ └───────────────┘
│ └───────────┘ │────┐ │ └───────────┘ │ │ │
│ ┌───────────┐ │ │ │ │ │ ┌───────────┐ │ ┌───────────────┐
│ │ 3.k │ │ │ │ │ │ │ KCLResult │──┼────────▶│x.Get("k", &v) │
│ └───────────┘ │ │ │ │ │ └───────────┘ │ └───────────────┘
│ ┌───────────┐ │ ├───▶│ ┌───────────┐ │──────────▶│ │
│ │setting.yml│ │ │ │ │RunFiles() │ │ │ ┌───────────┐ │ ┌───────────────┐
│ └───────────┘ │ │ │ └───────────┘ │ │ │ KCLResult │──┼────────▶│x.JSONString() │
└─────────────────┘ │ │ │ │ └───────────┘ │ └───────────────┘
│ │ │ │ │
┌─────────────────┐ │ │ │ │ ┌───────────┐ │ ┌───────────────┐
│ Options │ │ │ ┌───────────┐ │ │ │ KCLResult │──┼────────▶│x.YAMLString() │
│WithOptions │ │ │ │MustRun() │ │ │ └───────────┘ │ └───────────────┘
│WithOverrides │────┘ │ └───────────┘ │ │ │
│WithWorkDir │ │ │ │ │
│WithDisableNone │ │ │ │ │
└─────────────────┘ └─────────────────┘ └─────────────────┘
Example
Index
- func FormatCode(code interface{}) ([]byte, error)
- func FormatPath(path string) (changedPaths []string, err error)
- func InitKclvmRuntime(n int)
- func LintPath(path string) (results []string, err error)
- func OverrideFile(file string, specs []string) (bool, error)
- func RunPlayground(address string) error
- func ValidateCode(data, code string, opt *ValidateOptions) (ok bool, err error)
- type KCLResult
- type KCLResultList
- type KclType
- type Option
- func WithCode(codes ...string) Option
- func WithDisableNone(disableNone bool) Option
- func WithKFilenames(filenames ...string) Option
- func WithOptions(key_value_list ...string) Option
- func WithOverrides(override_list ...string) Option
- func WithPrintOverridesAST(printOverridesAST bool) Option
- func WithSettings(filename string) Option
- func WithWorkDir(workDir string) Option
- type ValidateOptions
func FormatCode
func FormatCode(code interface{}) ([]byte, error)
FormatCode returns the formatted code.
Example
func FormatPath
func FormatPath(path string) (changedPaths []string, err error)
FormatPath formats files from the given path path: if path is `.` or empty string\, all KCL files in current directory will be formatted\, not recursively if path is `path/file.k`\, the specified KCL file will be formatted if path is `path/to/dir`\, all KCL files in the specified dir will be formatted\, not recursively if path is `path/to/dir/...`\, all KCL files in the specified dir will be formatted recursively
the returned changedPaths are the changed file paths (relative path)
Example
func InitKclvmRuntime
func InitKclvmRuntime(n int)
InitKclvmRuntime init kclvm process.
func LintPath
func LintPath(path string) (results []string, err error)
LintPath lint files from the given path
Example
func OverrideFile
func OverrideFile(file string, specs []string) (bool, error)
OverrideFile rewrites a file with override spec file: string. The File that need to be overridden specs: []string. List of specs that need to be overridden. Each spec string satisfies the form: \<pkgpath>:\<field_path>=\<filed_value> or \<pkgpath>:\<field_path>- When the pkgpath is '__main__'\, it can be omitted.
func RunPlayground
func RunPlayground(address string) error
RunPlayground start KCL playground on given address.
Example
func ValidateCode
func ValidateCode(data, code string, opt *ValidateOptions) (ok bool, err error)
ValidateCode validate data match code
type KCLResult
type KCLResult = kcl.KCLResult
Example
Example ('et_struct)
func EvalCode
func EvalCode(code string) (*KCLResult, error)
type KCLResultList
type KCLResultList = kcl.KCLResultList
func MustRun
func MustRun(path string, opts ...Option) *KCLResultList
MustRun is like Run but panics if return any error.
Example
Example (Settings)
func Run
func Run(path string, opts ...Option) (*KCLResultList, error)
Run evaluates the KCL program with path and opts\, then returns the object list.
Example (Get Field)
func RunFiles
func RunFiles(paths []string, opts ...Option) (*KCLResultList, error)
RunFiles evaluates the KCL program with multi file path and opts\, then returns the object list.
Example
type KclType
type KclType = kcl.KclType
func GetSchemaType
func GetSchemaType(file, code, schemaName string) ([]*KclType, error)
GetSchemaType returns schema types from a kcl file or code.
file: string The kcl filename code: string The kcl code string schema_name: string The schema name got\, when the schema name is empty\, all schemas are returned.
type Option
type Option = kcl.Option
func WithCode
func WithCode(codes ...string) Option
WithCode returns a Option which hold a kcl source code list.
func WithDisableNone
func WithDisableNone(disableNone bool) Option
WithDisableNone returns a Option which hold a disable none switch.
func WithKFilenames
func WithKFilenames(filenames ...string) Option
WithKFilenames returns a Option which hold a filenames list.
func WithOptions
func WithOptions(key_value_list ...string) Option
WithOptions returns a Option which hold a key=value pair list for option function.
Example
func WithOverrides
func WithOverrides(override_list ...string) Option
WithOverrides returns a Option which hold a override list.
func WithPrintOverridesAST
func WithPrintOverridesAST(printOverridesAST bool) Option
WithPrintOverridesAST returns a Option which hold a printOverridesAST switch.
func WithSettings
func WithSettings(filename string) Option
WithSettings returns a Option which hold a settings file.
func WithWorkDir
func WithWorkDir(workDir string) Option
WithWorkDir returns a Option which hold a work dir.
type ValidateOptions
type ValidateOptions = validate.ValidateOptions
Generated by gomarkdoc