All Projects β†’ moul β†’ Protoc Gen Gotemplate

moul / Protoc Gen Gotemplate

Licence: mit
πŸ“‚ generic protocol generator based on golang's text/template (grpc/protobuf)

Programming Languages

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

Projects that are alternatives of or similar to Protoc Gen Gotemplate

protocell
Conjures up convenient OCaml types and serialization functions based on protobuf definition files
Stars: ✭ 18 (-93.66%)
Mutual labels:  protobuf, code-generator, protoc
powerproto
πŸŽ‰ An awesome version control tool for protoc and its related plugins.
Stars: ✭ 161 (-43.31%)
Mutual labels:  protobuf, protoc
protobuf-maven-plugin
Maven Plugin that executes the Protocol Buffers (protoc) compiler
Stars: ✭ 204 (-28.17%)
Mutual labels:  protobuf, protoc
gosproto
εŸΊδΊŽδΊ‘ι£Žηš„sprotoδΊŒθΏ›εˆΆζ ‡ε‡†δΈŠηš„ζθΏ°ζ–‡δ»ΆεŠδ»£η η”Ÿζˆε·₯ε…·
Stars: ✭ 52 (-81.69%)
Mutual labels:  protobuf, protoc
Query Translator
Query Translator is a search query translator with AST representation
Stars: ✭ 165 (-41.9%)
Mutual labels:  ast, generator
protokit
A starter kit for building protoc plugins. Rather than write your own, you can just use an existing one.
Stars: ✭ 69 (-75.7%)
Mutual labels:  protobuf, protoc
makego
Makefile setup for our Golang projects.
Stars: ✭ 65 (-77.11%)
Mutual labels:  protobuf, protoc
Reinforced.typings
Converts C# classes to TypeScript interfaces (and many more) within project build. 0-dependency, minimal, gluten-free
Stars: ✭ 341 (+20.07%)
Mutual labels:  ast, code-generator
protopatch
protoc-gen-go patch utility
Stars: ✭ 58 (-79.58%)
Mutual labels:  protobuf, protoc
docker-protobuf
An all-inclusive protoc Docker image
Stars: ✭ 105 (-63.03%)
Mutual labels:  protobuf, protoc
Csstree
A tool set for CSS including fast detailed parser, walker, generator and lexer based on W3C specs and browser implementations
Stars: ✭ 1,121 (+294.72%)
Mutual labels:  ast, generator
protoc-gen-kit
Protoc compiler for Go kit code
Stars: ✭ 17 (-94.01%)
Mutual labels:  protobuf, protoc
Astring
🌳 Tiny and fast JavaScript code generator from an ESTree-compliant AST.
Stars: ✭ 757 (+166.55%)
Mutual labels:  ast, code-generator
go2gql
graphql-go schema generator by proto files
Stars: ✭ 33 (-88.38%)
Mutual labels:  protobuf, protoc
Javaparser
Java 1-15 Parser and Abstract Syntax Tree for Java, including preview features to Java 13
Stars: ✭ 3,972 (+1298.59%)
Mutual labels:  ast, code-generator
proto2gql
The project has been migrated to https://github.com/EGT-Ukraine/go2gql.
Stars: ✭ 21 (-92.61%)
Mutual labels:  protobuf, protoc
Rules protobuf
Bazel rules for building protocol buffers and gRPC services (java, c++, go, ...)
Stars: ✭ 206 (-27.46%)
Mutual labels:  protobuf, protoc
Compodoc
πŸ“” The missing documentation tool for your Angular, Nest & Stencil application
Stars: ✭ 3,567 (+1155.99%)
Mutual labels:  ast, generator
protobuf-d
Protocol Buffers Compiler Plugin and Support Library for D
Stars: ✭ 32 (-88.73%)
Mutual labels:  protobuf, protoc
lowcode
React Lowcode - prototype, develop and maintain internal apps easier
Stars: ✭ 32 (-88.73%)
Mutual labels:  generator, ast

protoc-gen-gotemplate

πŸ“‚ protocol generator + golang text/template (protobuf)

A generic code/script/data generator based on Protobuf.


This project is a generator plugin for the Google Protocol Buffers compiler (protoc).

The plugin parses protobuf files, generates an ast, and walks a local templates directory to generate files using the Golang's text/template engine.

Philosophy

  • protobuf-first
  • no built-in template, only user defined templates
  • kiss, keep it stupid simple

Under the hood

  1. the user protobuf files are parsed by protoc
  2. the ast is generated by protoc-gen-go helpers
  3. the ast is given to Golang's text/template engine for each user template files
  4. the funcmap enriching the template engine is based on Masterminds/sprig, and contains type-manipulation, iteration and language-specific helpers

Web editor

Web editor screenshot

Demo server

Usage

protoc-gen-gotemplate requires a template_dir directory (by default ./templates).

Every file ending with .tmpl will be processed and written to the destination folder, following the file hierarchy of the template_dir, and remove the .tmpl extension.


$> ls -R
input.proto     templates/doc.txt.tmpl      templates/config.json.tmpl
$> protoc --gotemplate_out=. input.proto
$> ls -R
input.proto     templates/doc.txt.tmpl      templates/config.json.tmpl
doc.txt         config.json

Options

You can specify custom options, as follow:

$> protoc --gotemplate_out=debug=true,template_dir=/path/to/template/directory:. input.proto
Option Default Value Accepted Values Description
template_dir       ./template absolute or relative path path to look for templates
destination_dir     .           absolute or relative path base path to write output
single-package-mode false true or false if true, protoc won't accept multiple packages to be compiled at once (!= from all), but will support Message lookup across the imported protobuf dependencies
debug               false       true or false if true, protoc will generate a more verbose output
all                 false       true or false         if true, protobuf files without Service will also be parsed
Hints

Shipping the templates with your project is very smart and useful when contributing on git-based projects.

Another workflow consists in having a dedicated repository for generic templates which is then versioned and vendored with multiple projects (npm package, golang vendor package, ...)

See examples.

Funcmap

This project uses Masterminds/sprig library and additional functions to extend the builtin text/template helpers.

Non-exhaustive list of new helpers:

  • all the functions from sprig
  • add
  • boolFieldExtension
  • camelCase
  • contains
  • divide
  • fieldMapKeyType
  • fieldMapValueType
  • first
  • getEnumValue
  • getMessageType
  • getProtoFile
  • goNormalize
  • goTypeWithPackage
  • goType
  • goZeroValue
  • haskellType
  • httpBody
  • httpPath
  • httpPathsAdditionalBindings
  • httpVerb
  • index
  • int64FieldExtension
  • isFieldMap
  • isFieldMessageTimeStamp
  • isFieldMessage
  • isFieldRepeated
  • jsSuffixReserved
  • jsType
  • json
  • kebabCase
  • last
  • leadingComment
  • leadingDetachedComments
  • lowerCamelCase
  • lowerFirst
  • lowerGoNormalize
  • multiply
  • namespacedFlowType
  • prettyjson
  • replaceDict
  • shortType
  • snakeCase
  • splitArray
  • stringFieldExtension
  • stringMethodOptionsExtension
  • string
  • subtract
  • trailingComment
  • trimstr
  • upperFirst
  • urlHasVarsFromMessage

See the project helpers for the complete list.

Install

  • Install the Go compiler and tools from https://golang.org/doc/install
  • Install protobuf: go get -u github.com/golang/protobuf/{proto,protoc-gen-go}
  • Install protoc-gen-gotemplate: go get -u moul.io/protoc-gen-gotemplate

Docker

Usage:

$> docker run --rm -v "$(pwd):$(pwd)" -w "$(pwd)" moul/protoc-gen-gotemplate -I. --gotemplate_out=./output/ ./*.proto

Projects using protoc-gen-gotemplate

  • kafka-gateway: Kafka gateway/proxy (gRPC + http) using Go-Kit
  • translator: Translator Micro-service using Gettext and Go-Kit
  • acl: ACL micro-service (gRPC/protobuf + http/json)

See also

  • pbhbs: protobuf gen based on handlebarjs template

License

MIT

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].