Code Monkey home page Code Monkey logo

protoc-go-inject-tag's Introduction

protoc-go-inject-tag

Build Status Go Report Card Coverage Status

Why?

Golang protobuf doesn't support custom tags to generated structs. This script injects custom tags to generated protobuf files, useful for things like validation struct tags.

Install

  • protobuf version 3

    For OS X:

    brew install protobuf
    
  • go support for protobuf: go get -u github.com/golang/protobuf/{proto,protoc-gen-go}

  • go get github.com/favadi/protoc-go-inject-tag or download the binaries from releases page.

Usage

Add a comment with syntax // @inject_tag: custom_tag:"custom_value" before fields to add custom tag to in .proto files.

Example:

// file: test.proto
syntax = "proto3";

package pb;

message IP {
  // @inject_tag: valid:"ip"
  string Address = 1;
}

Generate with protoc command as normal.

protoc --go_out=. test.proto

Run protoc-go-inject-tag with generated file test.pb.go.

protoc-go-inject-tag -input=./test.pb.go

The custom tags will be injected to test.pb.go.

type IP struct {
	// @inject_tag: valid:"ip"
	Address string `protobuf:"bytes,1,opt,name=Address,json=address" json:"Address,omitempty" valid:"ip"`
}

To skip the tag for the generated XXX_* fields, use -XXX_skip=yaml,xml flag.

To enable verbose logging, use -verbose

protoc-go-inject-tag's People

Contributors

favadi avatar matthewtsmith avatar houjunchen avatar gabstv avatar binhnguyenduc avatar msolimans avatar credli avatar komkom avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.