Skip to content
A starter kit for building protoc plugins. Rather than write your own, you can just use an existing one.
Branch: master
Clone or download
Pull request Compare This branch is even with pseudomuto:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
examples/jsonator
fixtures
utils
.gitignore
.gofmtignore
.travis.yml
CHANGELOG.md
Gopkg.lock
Gopkg.toml
LICENSE
Makefile
README.md
comments.go
comments_test.go
context.go
context_test.go
doc.go
example_plugin_test.go
parser.go
parser_bench_test.go
parser_test.go
plugin.go
plugin_test.go
tools.json
types.go
version.go

README.md

protokit

Travis Build Status codecov GoDoc Go Report Card

A starter kit for building protoc-plugins. Rather than write your own, you can just use an existing one.

See the examples directory for uh...examples.

Getting Started

package main

import (
    "github.com/golang/protobuf/proto"
    "github.com/golang/protobuf/protoc-gen-go/plugin"
    "github.com/pseudomuto/protokit"
    _ "google.golang.org/genproto/googleapis/api/annotations" // Support (google.api.http) option (from google/api/annotations.proto).

    "log"
)

func main() {
    // all the heavy lifting done for you!
    if err := protokit.RunPlugin(new(plugin)); err != nil {
        log.Fatal(err)
    }
}

// plugin is an implementation of protokit.Plugin
type plugin struct{}

func (p *plugin) Generate(in *plugin_go.CodeGeneratorRequest) (*plugin_go.CodeGeneratorResponse, error) {
    descriptors := protokit.ParseCodeGenRequest(req)

    resp := new(plugin_go.CodeGeneratorResponse)

    for _, d := range descriptors {
        // TODO: YOUR WORK HERE
        fileName := // generate a file name based on d.GetName()
        content := // generate content for the output file

        resp.File = append(resp.File, &plugin_go.CodeGeneratorResponse_File{
            Name:    proto.String(fileName),
            Content: proto.String(content),
        })
    }

    return resp, nil
}

Then invoke your plugin via protoc. For example (assuming your app is called thingy):

protoc --plugin=protoc-gen-thingy=./thingy -I. --thingy_out=. rpc/*.proto

You can’t perform that action at this time.