All Projects → srikrsna → Protoc Gen Gotag

srikrsna / Protoc Gen Gotag

Licence: mit
Add custom struct tags to protobuf generated structs

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Protoc Gen Gotag

Kong
Kong is a command-line parser for Go
Stars: ✭ 481 (+395.88%)
Mutual labels:  struct, tags
Vue Gl
Vue.js components rendering 3D WebGL graphics reactively with three.js
Stars: ✭ 434 (+347.42%)
Mutual labels:  custom, tags
fieldmask-utils
Protobuf Field Mask Go utils
Stars: ✭ 127 (+30.93%)
Mutual labels:  protobuf, struct
Nb Choices
Angular wrapper for choices.js, vanilla, lightweight, configurable select box/text input plugin
Stars: ✭ 32 (-67.01%)
Mutual labels:  custom, tags
Flow Pipeline
A set of tools and examples to run a flow-pipeline (sFlow, NetFlow)
Stars: ✭ 86 (-11.34%)
Mutual labels:  protobuf
React Categorized Tag Input
React.js component for making tag autocompletion inputs with categorized results.
Stars: ✭ 78 (-19.59%)
Mutual labels:  tags
Fritzing Custom Parts
Fritzing-Custom-Parts
Stars: ✭ 76 (-21.65%)
Mutual labels:  custom
Grpcdump
Tool for capture and parse grpc traffic
Stars: ✭ 75 (-22.68%)
Mutual labels:  protobuf
Ngx Select Dropdown
Custom Dropdown for Angular 4+ with multiple and single selection options
Stars: ✭ 91 (-6.19%)
Mutual labels:  custom
Dots
just dotfiles ¯\_(ツ)_/¯
Stars: ✭ 90 (-7.22%)
Mutual labels:  custom
Uitabbaritem Custombadge
UITabBarItem+CustomBadge is a workaround to change the aspect of IOS UIBadgeView
Stars: ✭ 84 (-13.4%)
Mutual labels:  custom
Easyrpc
EasyRpc is a simple, high-performance, easy-to-use RPC framework based on Netty, ZooKeeper and ProtoStuff.
Stars: ✭ 79 (-18.56%)
Mutual labels:  protobuf
Omfm
Another floating action button menu with expand/collapse behavior, in kotlin
Stars: ✭ 86 (-11.34%)
Mutual labels:  custom
Curaengine
Powerful, fast and robust engine for converting 3D models into g-code instructions for 3D printers. It is part of the larger open source project Cura.
Stars: ✭ 1,207 (+1144.33%)
Mutual labels:  protobuf
Protobuf Nim
Protobuf implementation in pure Nim that leverages the power of the macro system to not depend on any external tools
Stars: ✭ 90 (-7.22%)
Mutual labels:  protobuf
Actix Protobuf
Protobuf integration for actix web
Stars: ✭ 75 (-22.68%)
Mutual labels:  protobuf
Sparksql Protobuf
Read SparkSQL parquet file as RDD[Protobuf]
Stars: ✭ 82 (-15.46%)
Mutual labels:  protobuf
Tagging
🏷 Type-safe tags in Swift
Stars: ✭ 89 (-8.25%)
Mutual labels:  tags
React Tagsinput
Highly customizable React component for inputing tags.
Stars: ✭ 1,241 (+1179.38%)
Mutual labels:  tags
Ue4protobuf
A protobuf source integration for UE4.
Stars: ✭ 80 (-17.53%)
Mutual labels:  protobuf

protoc-gen-gotag (PGGT)

PGGT is a protoc plugin used to add/replace struct tags on generated protobuf messages. Get it using go get github.com/srikrsna/protoc-gen-gotagIt supports the following features,

Add/Replace Tags

New tags like xml, sql, bson etc... can be added to struct messages of protobuf. Example

syntax = "proto3";

package example;

import "tagger/tagger.proto";

message Example {
    string with_new_tags = 1 [(tagger.tags) = "graphql:\"withNewTags,optional\"" ];
    string with_new_multiple = 2 [(tagger.tags) = "graphql:\"withNewTags,optional\" xml:\"multi,omitempty\"" ];
    
    string replace_default = 3 [(tagger.tags) = "json:\"replacePrevious\""] ; 

    oneof one_of {
        option (tagger.oneof_tags) = "graphql:\"withNewTags,optional\"";
        string a = 5 [(tagger.tags) = "json:\"A\""];
        int32 b_jk = 6 [(tagger.tags) = "json:\"b_Jk\""];
    }
}

message SecondMessage {
    string with_new_tags = 1 [(tagger.tags) = "graphql:\"withNewTags,optional\"" ];
    string with_new_multiple = 2 [(tagger.tags) = "graphql:\"withNewTags,optional\" xml:\"multi,omitempty\"" ];
    
    string replace_default = 3 [(tagger.tags) = "json:\"replacePrevious\""] ; 
}

Then struct tags can be added by running this command after the regular protobuf generation command.

    protoc -I /usr/local/include \
    	-I . \
    	--gotag_out=:. example/example.proto

In the above example tags like graphql and xml will be added whereas existing tags such as json are replaced with the supplied values.

Auto add tags on field

Automatically add custom tags to message field using provided transformer. It will compile the tag as tag:"snaked_key_name" by default if no transformer is being provide. To provide transformer, use: tagName-as-transformer instruction when running gotag

    protoc -I /usr/local/include \
    	-I . \
    	--gotag_out=auto="form+db-as-camel":. example/example.proto

The above command will add two addtional tags (form and db) for each field. The form tag will be lower_snake_case and db tag will be lowerCamelCase

Supported transformers:

Keys Action Ex
"lower_snake", "lower_snake_case", "snake", "snake_case" Make lower snake case key someKey -> some_key
"upper_snake", "upper_snake_case" Make upper snake case key someKey -> Some_key
"lower_camel", "lower_camel_case", "camel", "camel_case" Make lower camel case key someKey -> someKey
"upper_camel", "upper_camel_case" Make upper camel case key someKey -> SomeKey
"dot_notation", "dot", "lower_dot_notation", "lower_dot" Make lower cased dot notation key someKey -> some.key
"upper_dot", "upper_dot_notation" Make upper cased dot notation key someKey -> Some.Key

Add tags to XXX* fields

It is very useful to ignore XXX* fields in protobuf generated messages. The go protocol buffer compiler adds json:"-" tag to all XXX* fields. Additional tags can be added to these fields using the 'xxx' option of PGGT. It can be done like this. All '+' characters will be replaced with ':'.

    protoc -I /usr/local/include \
    	-I . \
    	--gotag_out=xxx="graphql+\"-\" bson+\"-\"":. example/example.proto

Note

This should always run after protocol buffer compiler has run. The command such as the one below will fail/produce unexpected results.

   protoc -I /usr/local/include \
       	-I . \
       	--go_out=:. \
       	--gotag_out=xxx="graphql+\"-\" bson+\"-\"":. example/example.proto
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].