Add Protocol Buffer Message Generation to Types Plugin #211
+634
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds Protocol Buffer (proto3) message generation to the types plugin, enabling developers to generate both Go types and protobuf definitions from a single Goa DSL source. This provides a unified approach to type definition across Go services and protobuf-based systems.
Motivation
The types plugin currently generates Go types and validations, which is great for Go-based microservices. However, many systems need to interoperate with:
By adding protobuf generation, the types plugin becomes a single source of truth for both Go and protobuf type definitions, eliminating the need to maintain parallel type systems.
Features
Complete Type Mapping Support
Boolean
bool
bool
Int
,Int32
int
,int32
int32
Int64
int64
int64
UInt
,UInt32
uint
,uint32
uint32
UInt64
uint64
uint64
Float32
float32
float
Float64
float64
double
String
string
string
Bytes
[]byte
bytes
Any
interface{}
google.protobuf.Any
ArrayOf(T)
[]T
repeated T
MapOf(K,V)
map[K]V
map<K, V>
Advanced Features
repeated
fieldsgoogle/protobuf/any.proto
optional
modifier for non-required fieldsExample
Input: Goa DSL
Output 1: Go Types (
gen/types/types.go
)Output 2: Proto Messages (
gen/types/types.proto
)Usage
Simply import the types plugin as before:
Run
goa gen
and you'll get both:gen/types/types.go
(Go types + validation)gen/types/types.proto
(Protocol Buffer messages)Use Cases
Compatibility
Documentation
The README has been updated with:
protoc