Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
C

cog

> 编程语言
Open source

Code Generation with a human touch

100 stars0 likes1 views
WebsiteGitHub

About

Code Generation with a human touch

cog

cog is a Code generator created with the following objectives in mind:

  • Support multiple schema formats: CUE, JSON Schema, OpenAPI, ...
  • Generate code in a wide range of languages: Golang, Java, PHP, Python, Typescript, …
  • Generate types described by schemas
  • Generate developer-friendly builder libraries, allowing the creation of complex objects as-code

Example use-cases

  • The Grafana Foundation SDK is fully generated by cog, from a collection of schemas exposed by Grafana
  • Grafana itself uses cog 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.
  • The grafana-app-sdk uses cog as a library for some of its code generation needs.

[!TIP] While cog is built and maintained by Grafana Labs, it is completely schema-agnostic.

Usage

As a CLI

Download the cog binary from our releases, and run the codegen pipeline:

bash
cog generate --config ./cog-pipeline.yaml

As a Go Library

See the Go documentation for more example and a complete API reference.

go
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))
}

Maturity

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.

Contributing

See our contributing guide.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Go

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言