mirror of
https://github.com/grafana/grafana.git
synced 2025-07-28 21:22:19 +08:00

* Update to latest cog version and update workspaces * Update generated go files * Try to avoid concurrency issues * Update workspaces * Try to remove the sync... * Remove grafana dependency from xorm go.mod file
42 lines
885 B
Go
42 lines
885 B
Go
package codegen
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"cuelang.org/go/cue"
|
|
"github.com/dave/dst/dstutil"
|
|
"github.com/grafana/codejen"
|
|
"github.com/grafana/cog"
|
|
)
|
|
|
|
type GoSpecJenny struct {
|
|
ApplyFuncs []dstutil.ApplyFunc
|
|
}
|
|
|
|
func (jenny *GoSpecJenny) JennyName() string {
|
|
return "GoResourceTypes"
|
|
}
|
|
|
|
func (jenny *GoSpecJenny) Generate(sfg ...SchemaForGen) (codejen.Files, error) {
|
|
files := make(codejen.Files, len(sfg))
|
|
|
|
for i, v := range sfg {
|
|
packageName := strings.ToLower(v.Name)
|
|
cueValue := v.CueFile.LookupPath(cue.ParsePath("lineage.schemas[0].schema"))
|
|
|
|
b, err := cog.TypesFromSchema().
|
|
CUEValue(packageName, cueValue).
|
|
Golang(cog.GoConfig{}).
|
|
Run(context.Background())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
files[i] = *codejen.NewFile(fmt.Sprintf("pkg/kinds/%s/%s_spec_gen.go", packageName, packageName), b[0].Data, jenny)
|
|
}
|
|
|
|
return files, nil
|
|
}
|