Skip to content

xapi-tools/protodefgen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

protodefgen - Protocol Buffer Definition Generator

This package provides Go structures for definitions used in Protocol Buffer file and a helper to write those constructs to .proto file with valid syntax.

Usage

  1. Get the package

    go get github.com/xapi-tools/protodefgen@latest
  2. Create Go structures for Protocol Buffers and generate file

    package main
    
    import pfg "github.com/xapi-tools/protodefgen"
    
    func main() {
        pw := pfg.NewProtoDefWriter(
            &pfg.Proto{
                Package: "test",
                Imports: []string{"google/protobuf/empty.proto"},
                Messages: []pfg.Message{
                    {
                        Name:        "BasicType",
                        Description: "This message contains basic types",
                        Fields: []pfg.MessageField{
                            {
                                Description: "This is required string field",
                                Name:        "name",
                                Type:        "string",
                                Id:          0,
                            },
                        },
                    },
                },
                Services: []pfg.Service{
                    {
                        Name:        "BasicService",
                        Description: "This is a service exercising BasicType",
                        Methods: []pfg.ServiceMethod{
                            {
                                Name:        "GetBasic",
                                Description: "Get BasicType",
                                Request:     "google.protobuf.Empty",
                                Response:    "BasicType",
                            },
                        },
                    },
                },
            },
            &pfg.ProtoWriterOpts{
                IndentWidth: 4,
            },
        )
    
        pw.ToFile("./test.proto")
    }

    Check following for more comprehensive examples:

About

Protocol Buffer Definition Generator

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages