Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate amqp protocol buffers in go
- Loading branch information
Jeff Jenkins
committed
Dec 15, 2015
1 parent
346c803
commit db33144
Showing
2 changed files
with
178 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package main | ||
|
||
import ( | ||
"text/template" | ||
) | ||
|
||
var protoTemplate *template.Template | ||
|
||
func init() { | ||
t, err := template.New("proto").Parse(`package amqp; | ||
import "github.com/gogo/protobuf/gogoproto/gogo.proto"; | ||
import "amqp/amqp.proto"; | ||
option (gogoproto.marshaler_all) = true; | ||
option (gogoproto.sizer_all) = true; | ||
option (gogoproto.unmarshaler_all) = true; | ||
{{range .Amqp.Classes}} | ||
{{if .Fields}} | ||
message {{.NormName}}ContentHeaderProperties { | ||
{{range $index, $field := .Fields}} | ||
optional{{.ProtoType}} {{.ProtoName}} = {{.ProtoIndex}}{{.Options}};{{end}} | ||
} | ||
{{end}} | ||
{{range .Methods}} | ||
message {{.NormName}} { | ||
option (gogoproto.goproto_unrecognized) = false; | ||
option (gogoproto.goproto_getters) = false; | ||
{{range $index, $field := .Fields}} | ||
optional{{.ProtoType}} {{.ProtoName}} = {{.ProtoIndex}}{{.Options}};{{end}} | ||
} | ||
{{end}} | ||
{{end}} | ||
`) | ||
if err != nil { | ||
panic(err.Error()) | ||
} | ||
protoTemplate = t | ||
} |