Files
grafana/pkg/codegen/jenny_go_spec.go
Selene e128c36127 Codegen: Cog and go fixes (#101408)
* 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
2025-03-12 10:12:56 +01:00

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
}