protoc-gen-gotags

command module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 3, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

README

protoc-gen-gotags

Build Status codeCov

What is this?

In protoc-gen-go, it is difficult to customize tags such as gorm, db, etc. You can use this tool to add any tag you need to the go field.

Install

Download in release page or use go install

go install github.com/eirueirufu/protoc-gen-gotags@latest

Usage

  1. define the options
  2. use protoc-gen-go to generate your .pb.go file
  3. use protoc-gen-gotags to replace the generated .pb.go file tags, in this cmd, you should set opt param go_out to specify protoc-gen-go out_dir, such as --gotags_opt=go_out=.

field options example:

syntax = "proto3";

package example;

import "options.proto";

......

message Msg {
    string append_tag = 1 [(gotags.tag) = {
        key: "append_key",
        value: "msg_append_value",
    }];
    string replace_tag = 2 [(gotags.tag) = {
        key: "json",
        value: "msg_replace_json_value",
    }];
    string append_tags = 3 [
        (gotags.tag) = {
            key: "append_key1",
            value: "msg_append_value1",
        },
        (gotags.tag) = {
            key: "append_key2",
            value: "msg_append_value2",
        }
    ];
    string replace_tags = 4 [
        (gotags.tag) = {
            key: "protobuf",
            value: "msg_replace_proto_value",
        },
        (gotags.tag) = {
            key: "json",
            value: "msg_replace_json_value",
        }
    ];
    string replace_and_append_tags = 5 [
        (gotags.tag) = {
            key: "json",
            value: "msg_replace_json_value",
        },
        (gotags.tag) = {
            key: "append_key",
            value: "msg_append_value",
        }
    ];
    string all = 6 [(gotags.all) = "all:\"msg_all\""];
}

before:

type Msg struct {
	state         protoimpl.MessageState
	sizeCache     protoimpl.SizeCache
	unknownFields protoimpl.UnknownFields

	AppendTag            string `protobuf:"bytes,1,opt,name=append_tag,json=appendTag,proto3" json:"append_tag,omitempty"`
	ReplaceTag           string `protobuf:"bytes,2,opt,name=replace_tag,json=replaceTag,proto3" json:"replace_tag,omitempty"`
	AppendTags           string `protobuf:"bytes,3,opt,name=append_tags,json=appendTags,proto3" json:"append_tags,omitempty"`
	ReplaceTags          string `protobuf:"bytes,4,opt,name=replace_tags,json=replaceTags,proto3" json:"replace_tags,omitempty"`
	ReplaceAndAppendTags string `protobuf:"bytes,5,opt,name=replace_and_append_tags,json=replaceAndAppendTags,proto3" json:"replace_and_append_tags,omitempty"`
	All                  string `protobuf:"bytes,6,opt,name=all,proto3" json:"all,omitempty"`
}

after:

type Msg struct {
	state         protoimpl.MessageState
	sizeCache     protoimpl.SizeCache
	unknownFields protoimpl.UnknownFields

	AppendTag            string `protobuf:"bytes,1,opt,name=append_tag,json=appendTag,proto3" json:"append_tag,omitempty" append_key:"msg_append_value"`
	ReplaceTag           string `protobuf:"bytes,2,opt,name=replace_tag,json=replaceTag,proto3" json:"msg_replace_json_value"`
	AppendTags           string `protobuf:"bytes,3,opt,name=append_tags,json=appendTags,proto3" json:"append_tags,omitempty" append_key1:"msg_append_value1" append_key2:"msg_append_value2"`
	ReplaceTags          string `protobuf:"msg_replace_proto_value" json:"msg_replace_json_value"`
	ReplaceAndAppendTags string `protobuf:"bytes,5,opt,name=replace_and_append_tags,json=replaceAndAppendTags,proto3" json:"msg_replace_json_value" append_key:"msg_append_value"`
	All                  string `all:"msg_all"`
}

License

See LICENSE.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL