The Agent build tools support easy integration of protobuf data format definitions into your program.
- Define your data formats as a set of messages in a google protobuf
file. For a simple example, see
examples/model/example.proto
. - In the plugin's main file (for example,
etcd/main.go
), add the following line at the top of the file:
// go:generate protoc --proto_path=examples/model --go_out=examples/model examples/model/example.proto
- You can have multiple files with protobuf message definitions. Add a similar line for each file.
- The above line will instruct the go tool to use the
protoc
code generator to generate go structures from protobuf messages defined in theexample.proto
file. The line also specifies the path to the file and the location where to put the generated structures (in our example, all are the same,examples/model
). - Do
make generate
to generate go structures from protobuf message definitions. The structures will be put intoexample.pb.go
in the same folder. The structures will be annotated with protobuf annotations to support marshalling/un-marshalling at run-time.
You can now use the generated go structures in your code.