Skip to content
Protobuf code generation for micro
Branch: master
Clone or download
asim Revert "Fixes issue #12 that prevents protoc-gen-micro from importing…
… protobufs in the same folder."

This reverts commit bc0767c.
Latest commit 8936c52 Mar 14, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples/greeter Handle server Handle() error Jul 27, 2018
generator Revert "Fixes issue #12 that prevents protoc-gen-micro from importing… Mar 15, 2019
plugin/micro Correctly format generated code Dec 11, 2018
.travis.yml Update Feb 13, 2019
go.sum Add go mod Jan 30, 2019
main.go change protoc-gen-go to protoc-gen-micro Feb 28, 2018


This is protobuf code generation for micro. We use protoc-gen-micro to reduce boilerplate code.


go get

Also required:


Define your service as greeter.proto

syntax = "proto3";

service Greeter {
	rpc Hello(Request) returns (Response) {}

message Request {
	string name = 1;

message Response {
	string msg = 1;

Generate the code

protoc --proto_path=$GOPATH/src:. --micro_out=. --go_out=. greeter.proto

Your output result should be:

    greeter.proto	# original protobuf file
    greeter.pb.go	# auto-generated by protoc-gen-go
    greeter.micro.go	# auto-generated by protoc-gen-micro

The micro generated code includes clients and handlers which reduce boiler plate code


Register the handler with your micro server

type Greeter struct{}

func (g *Greeter) Hello(ctx context.Context, req *proto.Request, rsp *proto.Response) error {
	rsp.Msg = "Hello " + req.Name
	return nil

proto.RegisterGreeterHandler(service.Server(), &Greeter{})


Create a service client with your micro client

client := proto.NewGreeterService("greeter", service.Client())


If you see an error about protoc-gen-micro not being found or executable, it's likely your environment may not be configured correctly. If you've already installed protoc, protoc-gen-go, and protoc-gen-micro ensure you've included $GOPATH/bin in your PATH.

Alternative specify the Go plugin paths as arguments to the protoc command

protoc --plugin=protoc-gen-go=$GOPATH/bin/protoc-gen-go --plugin=protoc-gen-micro=$GOPATH/bin/protoc-gen-micro --proto_path=$GOPATH/src:. --micro_out=. --go_out=. greeter.proto


protoc-gen-micro is a liberal reuse of protoc-gen-go hence we maintain the original license

You can’t perform that action at this time.