protoc-gen-sphere
Generates HTTP server code from .proto
service definitions, using google.api.http
annotations and Sphere server utilities (Gin-based).
Install
go install github.com/go-sphere/protoc-gen-sphere@latest
Key Flags
version
: print versionomitempty
: skip files withoutgoogle.api.http
(default true)omitempty_prefix
: apply omitempty only to prefixed pathstemplate_file
: custom go text/templateswagger_auth_header
: auth header comment for Swaggerrouter_type
: router type (defaultgithub.com/gin-gonic/gin;IRouter
)context_type
: context type (defaultgithub.com/gin-gonic/gin;Context
)data_resp_type
: data model with generics (defaultgithub.com/go-sphere/sphere/server/ginx;DataResponse
)error_resp_type
: error model (defaultgithub.com/go-sphere/sphere/server/ginx;ErrorResponse
)server_handler_func
: wrapper (defaultgithub.com/go-sphere/sphere/server/ginx;WithJson
)parse_json_func
,parse_uri_func
,parse_form_func
: request parsing hooks
Buf Example
version: v2
managed:
enabled: true
disable:
- file_option: go_package_prefix
module: buf.build/googleapis/googleapis
- file_option: go_package_prefix
module: buf.build/bufbuild/protovalidate
override:
- file_option: go_package_prefix
value: github.com/go-sphere/sphere-layout/api
plugins:
- local: protoc-gen-sphere
out: api
opt:
- paths=source_relative
- swagger_auth_header=// @Security ApiKeyAuth
Notes
- Works hand-in-hand with Sphere’s Gin helpers:
WithJson
,ShouldBindJSON
,ShouldBindUri
,ShouldBindQuery
- Pair with
protoc-gen-sphere-binding
to inject binding tags into generated structs
Last updated on