All Projects → microhq → Protoc Gen Micro

microhq / Protoc Gen Micro

Protobuf code generation for Micro. Moved to go-micro/cmd/protoc-gen-micro.

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Protoc Gen Micro

protoc-gen-micro
Protobuf code generation
Stars: ✭ 287 (+6.3%)
Mutual labels:  protobuf, micro, go-micro
Go Os
Stars: ✭ 185 (-31.48%)
Mutual labels:  go-micro, micro
Micro Starter Kit
Cloud Native GoLang Microservices - gRPC, GraphQL
Stars: ✭ 167 (-38.15%)
Mutual labels:  go-micro, micro
Nano
Lightweight, facility, high performance golang based game server framework
Stars: ✭ 1,888 (+599.26%)
Mutual labels:  protobuf, micro
S
a go web freamwork for micro service, very very easy to create and deploy, with auto service registry and discover, high performance and based on http/2 no ssl
Stars: ✭ 67 (-75.19%)
Mutual labels:  go-micro, micro
Go Plugins
Go Micro Plugins. Moved to go-micro/plugins.
Stars: ✭ 1,654 (+512.59%)
Mutual labels:  go-micro, micro
Go Shopping
A sample suite of services built on the go-micro framework
Stars: ✭ 98 (-63.7%)
Mutual labels:  protobuf, go-micro
Getty
a netty like asynchronous network I/O library based on tcp/udp/websocket; a bidirectional RPC framework based on JSON/Protobuf; a microservice framework based on zookeeper/etcd
Stars: ✭ 532 (+97.04%)
Mutual labels:  protobuf, micro
Wehousing
Golang微服务+区块链实战---go+micro+fabric实现租房上链系统
Stars: ✭ 182 (-32.59%)
Mutual labels:  protobuf, micro
MicroServicePractice
微服务实践的demo
Stars: ✭ 40 (-85.19%)
Mutual labels:  protobuf, go-micro
micro-starter
Micro 微服务实践
Stars: ✭ 391 (+44.81%)
Mutual labels:  micro, go-micro
Gomicro note
go-micro学习笔记
Stars: ✭ 62 (-77.04%)
Mutual labels:  go-micro, micro
Micro
go-micro 微服务实践,更多请关注Micro中国站☞
Stars: ✭ 383 (+41.85%)
Mutual labels:  go-micro, micro
Go Grpc
A simpler grpc framework
Stars: ✭ 133 (-50.74%)
Mutual labels:  go-micro, micro
Microservices
micro 微服务实例教程,包含JWT鉴权、熔断、监控、链路追踪、健康检查、跨域等
Stars: ✭ 341 (+26.3%)
Mutual labels:  go-micro, micro
Go Micro Boilerplate
The boilerplate of the GoLang application with a clear microservices architecture.
Stars: ✭ 147 (-45.56%)
Mutual labels:  protobuf, go-micro
RentHouseWeb
使用 go+docker+go-micro微服务框架开发的租房网系统,符合RESTful架构风格。
Stars: ✭ 28 (-89.63%)
Mutual labels:  protobuf, go-micro
micro-plugins
go-micro plugins, auth(JWT+Casbin)、go-micro服务加入istio服务网格
Stars: ✭ 27 (-90%)
Mutual labels:  micro, go-micro
grpcman
A grpc testing tool based on Electron & Vue.js & Element-UI
Stars: ✭ 22 (-91.85%)
Mutual labels:  protobuf
backend
Backend powering the M3O platform
Stars: ✭ 64 (-76.3%)
Mutual labels:  micro

protoc-gen-micro

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

Install

go get github.com/micro/protoc-gen-micro/v2

Also required:

Usage

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

Server

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{})

Client

Create a service client with your micro client

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

Errors

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

Endpoint

Add a micro API endpoint which routes directly to an RPC method

Usage:

  1. Clone github.com/googleapis/googleapis to use this feature as it requires http annotations.
  2. The protoc command must include -I$GOPATH/src/github.com/googleapis/googleapis for the annotations import.
syntax = "proto3";

import "google/api/annotations.proto";

service Greeter {
	rpc Hello(Request) returns (Response) {
		option (google.api.http) = { post: "/hello"; body: "*"; };
	}
}

message Request {
	string name = 1;
}

message Response {
	string msg = 1;
}

The proto generates a RegisterGreeterHandler function with a api.Endpoint.

func RegisterGreeterHandler(s server.Server, hdlr GreeterHandler, opts ...server.HandlerOption) error {
	type greeter interface {
		Hello(ctx context.Context, in *Request, out *Response) error
	}
	type Greeter struct {
		greeter
	}
	h := &greeterHandler{hdlr}
	opts = append(opts, api.WithEndpoint(&api.Endpoint{
		Name:    "Greeter.Hello",
		Path:    []string{"/hello"},
		Method:  []string{"POST"},
		Handler: "rpc",
	}))
	return s.Handle(s.NewHandler(&Greeter{h}, opts...))
}

LICENSE

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

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