Skip to content

How to use with buf #73

@darkliquid

Description

@darkliquid

I generally tend to use buf rather than directly calling protoc, so I had to do a bit of work to figure out how to make this work with that.

Here's my solution:

buf.yaml

version: v2
modules:
  - path: proto

buf.gen.yaml

version: v2
clean: true
managed:
  enabled: true
plugins:
  - local: ["go", "tool", "github.com/knqyf263/go-plugin/cmd/protoc-gen-go-plugin"]
    out: pkg
    opt:
      - paths=source_relative
    strategy: directory
    include_imports: true
    include_wkt: true

And added the following to my go.mod (making use of the new tool directive):

tool (
	github.com/bufbuild/buf/cmd/buf
	github.com/bufbuild/buf/cmd/protoc-gen-buf-breaking
	github.com/bufbuild/buf/cmd/protoc-gen-buf-lint
	github.com/knqyf263/go-plugin/cmd/protoc-gen-go-plugin
)

I can now run:

go tool buf generate

And have it generate the code from my proto folder into my pkg folder.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions