希曼日记

安装

IDE: https://buf.build/docs/editor-integration/

插件:

这个不是buf官方,但能用 protoc-gen-es:https://github.com/wasilibs/go-protoc-gen-es

buf,grpcurl,protoc-gen-go,protoc-gen-connect-go https://connectrpc.com/docs/go/getting-started

go install github.com/bufbuild/buf/cmd/buf@latest  
go install github.com/fullstorydev/grpcurl/cmd/grpcurl@latest  
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install connectrpc.com/connect/cmd/protoc-gen-connect-go@latest

配置:

# For details on buf.yaml configuration, visit https://buf.build/docs/configuration/v2/buf-yaml
version: v2
lint:
  use:
    - STANDARD
  except:
    - FIELD_NOT_REQUIRED
    - PACKAGE_NO_IMPORT_CYCLE
  disallow_comment_ignores: true
  ignore:
    - internal/conf
#deps: # 依赖的proto库
#  - buf.build/googleapis/googleapis
#  - buf.build/grpc-ecosystem/grpc-gateway
#  - buf.build/bufbuild/protovalidate
breaking:
  use:
    - FILE
  except:
    - EXTENSION_NO_DELETE
    - FIELD_SAME_DEFAULT

buf.gen.yaml

version: v2
managed:
  enabled: true
  disable:
    - module: buf.build/googleapis/googleapis
      file_option: go_package_prefix # 禁用对 googleapis 模块的 go_package 重写
    - file_option: go_package
      module: buf.build/bufbuild/protovalidate
#    - file_option: go_package
#      module: buf.build/grpc-ecosystem/grpc-gateway
#  override:
#    - file_option: go_package_prefix
#      value: connect-go-example/greet
plugins:
#  - remote: buf.build/grpc/go
#    out: .
#    opt: paths=source_relative
#  - remote: buf.build/protocolbuffers/go
#    out: gen
#    opt: paths=source_relative
  - local: protoc-gen-go
    out: gen
    opt: paths=source_relative
  - local: protoc-gen-connect-go
    out: gen
    opt: paths=source_relative
  # This will invoke protoc-gen-es and write output to src/gen
  - local: protoc-gen-es
    out: gen/web
    # Also generate any imported dependencies
    include_imports: true
    # Add more plugin options here
    opt: target=ts