diff options
author | Tim Swast <swast@google.com> | 2015-12-15 15:56:23 -0800 |
---|---|---|
committer | Tim Swast <swast@google.com> | 2015-12-15 15:56:23 -0800 |
commit | 1cc541b3be263d92aba435b183aca5ad7151ae8a (patch) | |
tree | a6e62dd8b8811529f555c436a206410eb49544ac /examples/add_person.go | |
parent | 1a59a715dc5fa584340197aac0811ba3de9850b5 (diff) | |
download | protobuf-1cc541b3be263d92aba435b183aca5ad7151ae8a.tar.gz protobuf-1cc541b3be263d92aba435b183aca5ad7151ae8a.tar.bz2 protobuf-1cc541b3be263d92aba435b183aca5ad7151ae8a.zip |
Add region tags to the Go protobuf examples.
This will allow us to like to specific snippets of code in the
documentation. I plan to create a tutorial similar to the C# tutorial
https://developers.google.com/protocol-buffers/docs/csharptutorial
Since that tutorial has sections for populating a proto, parsing, and
serializing, I made a region for each of these for Go. To make the
populating sample more self-contained, I refactor the listing example
slightly.
Diffstat (limited to 'examples/add_person.go')
-rw-r--r-- | examples/add_person.go | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/examples/add_person.go b/examples/add_person.go index 6b2d3d69..4f2e7f74 100644 --- a/examples/add_person.go +++ b/examples/add_person.go @@ -105,7 +105,10 @@ func main() { log.Fatalln("Error reading file:", err) } } + + // [START marshal_proto] book := &pb.AddressBook{} + // [START_EXCLUDE] if err := proto.Unmarshal(in, book); err != nil { log.Fatalln("Failed to parse address book:", err) } @@ -116,6 +119,7 @@ func main() { log.Fatalln("Error with address:", err) } book.People = append(book.People, addr) + // [END_EXCLUDE] // Write the new address book back to disk. out, err := proto.Marshal(book) @@ -125,4 +129,5 @@ func main() { if err := ioutil.WriteFile(fname, out, 0644); err != nil { log.Fatalln("Failed to write address book:", err) } + // [END marshal_proto] } |