Skip to content

A fork of the original protoc-go-inject-tag that improves the CLI, options, etc.

License

Notifications You must be signed in to change notification settings

stevezaluk/protoc-go-inject-tag

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contributors Forks Stargazers Issues MIT License LinkedIn


Logo

protoc-go-inject-tag

A command line tool for injecting custom struct tags into Protobuf's
Explore the docs »

Table of Contents
  1. About The Project
  2. Disclaimers
  3. Getting Started
  4. Contributing
  5. License
  6. Contact

About The Project

protoc-go-inject-tag is a command line tool for injecting custom struct tags into go-lang generated protobuf messages. I originally found a need for this when I was developing MTGJSON-API and needed a way to insert bson tags into the structs that protoc generated. This feature is not supported out of the box using protoc hence the need for this project to exist. Thsi was originally created by Favadi and I encourage you to check out his original repo

What has changed?

  • Fully featured Cobra CLI with Viper config management
  • Recursively parse all files in a directory without needing to use patterns
  • Proper verbosity and logging with log/slog
  • The ability to change the file extension to search for with --file-ext
  • Set your own comment prefix using --comment-prefix
  • Removed deprecation warning for @inject_tag

What will be included in the future?

  • A refactored API to simplify the injection process
  • Proper abstractions for TextArea and TagItems
  • The ability to set default tags for all fields (i.e. bson=camelCase)

Disclaimers

protoc-go-inject-tag originally created by Favadi, improved by Steven Zaluk

(back to top)

Getting Started

Realistically, nothing is needed to get started with this repo. All you need to do is pull the binary from the release's page and execute it to get started. However if you do not have any protobuf messages generated then you are going to need to install both protoc and the go lang support protoc-gen-go

You can see instructions for installing these in the "Prerequisites" section below this one

Prerequisites

To start install protoc using the following commands depending on your operating system

  • MacOS brew update && brew install protobuf
  • Debian Based Linux: apt update && apt install -y protobuf-compiler

You can validate that this is installed using the following command: protoc --version

Next install protoc-gen-go: go install google.golang.org/protobuf/cmd/protoc-gen-go@latest

Building

  1. Clone the repo
    git clone https://github.com/stevezaluk/mtgjson-api.git
  2. Install dependencies
    go get .
  3. Build the project
     go build
  4. View the help page
    ./protoc-go-inject-tag --help

Usage

Usage:
protoc-go-inject-tag inject [flags]

Flags:
--comment-prefix string   The prefix of the comment that protoc-go-inject-tag should search for when looking for tags to inject. A @ will be prefixed to this value (default "gotags")  -f, --file-ext string         The file extensions that should be considered for injection (default ".pb.go")
-h, --help                    help for inject
-i, --input string            The input path you want to search for protobufs with
--remove-comments         Remove comments from generated protobufs
--tags strings            Additional tags that should be applied to all fields (not implemented yet)
-v, --verbose                 Enable extended verbosity in logging

Global Flags:
--config string   config file (default is $HOME/config/protoc-go-inject-tag/config.json)

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

Distributed under Apache License 2.0. See LICENSE.txt for more information.

(back to top)

Contact

Steven A. Zaluk - @steve_zaluk

Project Link: https://github.com/stevezaluk/protoc-go-inject-tag\n

(back to top)

About

A fork of the original protoc-go-inject-tag that improves the CLI, options, etc.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%