Some checks are pending
Docs Deploy / build_and_deploy (push) Waiting to run
Generate Docs / cli (push) Waiting to run
Generate Config Doc / cli (push) Waiting to run
Go formatting / go-formatting (push) Waiting to run
Check links / markdown-link-check (push) Waiting to run
Integration / pre-test (push) Waiting to run
Integration / test on (push) Blocked by required conditions
Integration / status (push) Blocked by required conditions
Lint / Lint Go code (push) Waiting to run
Test / test (ubuntu-latest) (push) Waiting to run
58 lines
1.3 KiB
Markdown
58 lines
1.3 KiB
Markdown
---
|
|
sidebar_position: 14
|
|
title: Buf Integration (cosmosbuf)
|
|
slug: /packages/cosmosbuf
|
|
---
|
|
|
|
# Buf Integration (cosmosbuf)
|
|
|
|
The `cosmosbuf` package wraps Buf workflows (`generate`, `export`, `format`, `migrate`, `dep update`) used by Ignite's protobuf pipelines.
|
|
|
|
For full API details, see the
|
|
[`cosmosbuf` Go package documentation](https://pkg.go.dev/github.com/ignite/cli/v29/ignite/pkg/cosmosbuf).
|
|
|
|
## When to use
|
|
|
|
- Trigger Buf code generation from Go services.
|
|
- Keep Buf invocation flags and error handling consistent.
|
|
- Reuse cache-aware generation behavior.
|
|
|
|
## Key APIs
|
|
|
|
- `New(cacheStorage cache.Storage, goModPath string) (Buf, error)`
|
|
- `(Buf) Generate(ctx, protoPath, output, template, options...)`
|
|
- `(Buf) Format(ctx, path)`
|
|
- `(Buf) Export(ctx, protoDir, output)`
|
|
- `Version(ctx context.Context) (string, error)`
|
|
|
|
## Example
|
|
|
|
```go
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/ignite/cli/v29/ignite/pkg/cache"
|
|
"github.com/ignite/cli/v29/ignite/pkg/cosmosbuf"
|
|
)
|
|
|
|
func main() {
|
|
storage, err := cache.NewStorage(filepath.Join(os.TempDir(), "ignite-cache.db"))
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
buf, err := cosmosbuf.New(storage, "github.com/acme/my-chain")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
if err := buf.Format(context.Background(), "./proto"); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
```
|