Code Generation with a human touch
cog is a Code generator created with the following objectives in mind:
cog, from a collection of schemas exposed by Grafanacog to enable a schema-first approach where some
resources (example: dashboards)
are schematized first, then code is generated both for the frontend and
backend from those schemas.grafana-app-sdk uses cog
as a library for some of its code generation needs.[!TIP] While
cogis built and maintained by Grafana Labs, it is completely schema-agnostic.
Download the cog binary from our releases,
and run the codegen pipeline:
cog generate --config ./cog-pipeline.yamlSee the Go documentation for more example and a complete API reference.
package main
import (
"context"
"fmt"
"github.com/grafana/cog"
)
func main() {
files, err := cog.TypesFromSchema().
CUEModule("/path/to/cue/module").
SchemaTransformations(
cog.AppendCommentToObjects("Transformed by cog."),
cog.PrefixObjectsNames("Example"),
).
Golang(cog.GoConfig{}).
Run(context.Background())
if err != nil {
panic(err)
}
if len(files) != 1 {
panic("expected a single file :(")
}
fmt.Println(string(files[0].Data))
}Cog should be considered as "public preview". While it is used by Grafana Labs in production, it still is under active development.
Additional information can be found in Release life cycle for Grafana Labs.
[!NOTE] Bugs and issues are handled solely by Engineering teams. On-call support or SLAs are not available.
See our contributing guide.
No open issues yet, or sync has not completed.