Skip to content

Another protoc plugin to generate Go codes, and add customizing field tags and names support

License

Notifications You must be signed in to change notification settings

wizacklabs/protoc-gen-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

protc-gen-go

The protoc-gen-go project is another protoc plugin to generate Go code for both proto2 and proto3 versions of the protocol buffer language.

The protoc-gen-go works just like official utility, and provides some new features to auto generate message field tag and custimize field name from comments.

For more information about the usage of this plugin, see: https://protobuf.dev/reference/go/go-generated.

Features

  • auto generate message field tags from comments
  • customize message field name

Limitations

  • only works for message field declaration

Installation

go install github.com/derekhjray/proto-gen-go

Usage

  • auto generate field tags

    protobuf source code

    message foo {
        // @gorm.tag=column:id;autoIncrement
        // @json.tag=ID
        int64 id = 1;
    }

    generated go source code

    type Foo struct {
        state         protoimpl.MessageState
        sizeCache     protoimpl.SizeCache
        unknownFields protoimpl.UnknownFields
    
        Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"ID,omitempty" gorm:"column:id;autoIncrement"`
    }
  • customize field name

    protobuf source code

    message foo {
        // @go.name=ID
        int64 id = 1;
    }

    generated go source code

    type Foo struct {
        state         protoimpl.MessageState
        sizeCache     protoimpl.SizeCache
        unknownFields protoimpl.UnknownFields
    
        ID int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
    }

About

Another protoc plugin to generate Go codes, and add customizing field tags and names support

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published