Skip to content

Instantly share code, notes, and snippets.

Created Dec 17, 2015
What would you like to do?
Sample Golang implementation of spec.proto
// Code generated by protoc-gen-go.
// source: spec.proto
Package example is a generated protocol buffer package.
It is generated from these files:
It has these top-level messages:
package example
import proto ""
import fmt "fmt"
import math "math"
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
type CompanyType int32
const (
CompanyType_Private CompanyType = 17
CompanyType_Public CompanyType = 18
CompanyType_NonProfit CompanyType = 19
var CompanyType_name = map[int32]string{
17: "Private",
18: "Public",
19: "NonProfit",
var CompanyType_value = map[string]int32{
"Private": 17,
"Public": 18,
"NonProfit": 19,
func (x CompanyType) Enum() *CompanyType {
p := new(CompanyType)
*p = x
return p
func (x CompanyType) String() string {
return proto.EnumName(CompanyType_name, int32(x))
func (x *CompanyType) UnmarshalJSON(data []byte) error {
value, err := proto.UnmarshalJSONEnum(CompanyType_value, data, "CompanyType")
if err != nil {
return err
*x = CompanyType(value)
return nil
func (CompanyType) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
type Company struct {
Name *string `protobuf:"bytes,1,req,name=Name" json:"Name,omitempty"`
Employees []*Employee `protobuf:"bytes,2,rep,name=Employees" json:"Employees,omitempty"`
Type *CompanyType `protobuf:"varint,3,req,name=Type,enum=example.CompanyType" json:"Type,omitempty"`
Address *Company_Address `protobuf:"group,4,opt,name=Address" json:"address,omitempty"`
XXX_unrecognized []byte `json:"-"`
func (m *Company) Reset() { *m = Company{} }
func (m *Company) String() string { return proto.CompactTextString(m) }
func (*Company) ProtoMessage() {}
func (*Company) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
func (m *Company) GetName() string {
if m != nil && m.Name != nil {
return *m.Name
return ""
func (m *Company) GetEmployees() []*Employee {
if m != nil {
return m.Employees
return nil
func (m *Company) GetType() CompanyType {
if m != nil && m.Type != nil {
return *m.Type
return CompanyType_Private
func (m *Company) GetAddress() *Company_Address {
if m != nil {
return m.Address
return nil
type Company_Address struct {
Country *string `protobuf:"bytes,5,req,name=Country" json:"Country,omitempty"`
City *string `protobuf:"bytes,6,req,name=City" json:"City,omitempty"`
Street *string `protobuf:"bytes,7,opt,name=Street" json:"Street,omitempty"`
XXX_unrecognized []byte `json:"-"`
func (m *Company_Address) Reset() { *m = Company_Address{} }
func (m *Company_Address) String() string { return proto.CompactTextString(m) }
func (*Company_Address) ProtoMessage() {}
func (m *Company_Address) GetCountry() string {
if m != nil && m.Country != nil {
return *m.Country
return ""
func (m *Company_Address) GetCity() string {
if m != nil && m.City != nil {
return *m.City
return ""
func (m *Company_Address) GetStreet() string {
if m != nil && m.Street != nil {
return *m.Street
return ""
type Employee struct {
Name *string `protobuf:"bytes,1,req,name=Name" json:"Name,omitempty"`
SSN *string `protobuf:"bytes,2,opt,name=SSN" json:"SSN,omitempty"`
XXX_unrecognized []byte `json:"-"`
func (m *Employee) Reset() { *m = Employee{} }
func (m *Employee) String() string { return proto.CompactTextString(m) }
func (*Employee) ProtoMessage() {}
func (*Employee) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
func (m *Employee) GetName() string {
if m != nil && m.Name != nil {
return *m.Name
return ""
func (m *Employee) GetSSN() string {
if m != nil && m.SSN != nil {
return *m.SSN
return ""
func init() {
proto.RegisterType((*Company)(nil), "example.Company")
proto.RegisterType((*Company_Address)(nil), "example.Company.Address")
proto.RegisterType((*Employee)(nil), "example.Employee")
proto.RegisterEnum("example.CompanyType", CompanyType_name, CompanyType_value)
var fileDescriptor0 = []byte{
// 243 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x5c, 0x8f, 0xc1, 0x4a, 0xc4, 0x30,
0x14, 0x45, 0xe9, 0xb4, 0x36, 0xf6, 0x55, 0xc7, 0xce, 0xd3, 0x45, 0x70, 0x55, 0x8a, 0x42, 0x75,
0xd1, 0x45, 0x41, 0x70, 0x2b, 0x83, 0x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c,
0xb5, 0x7c, 0xeb, 0x6d, 0x76, 0xf9, 0x15, 0x00, 0x00, 0xff, 0xff, 0xec, 0x74, 0xf0, 0x0d, 0x3c,
0x01, 0x00, 0x00,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment