All Projects → go-microdev → protoc-gen-micro

go-microdev / protoc-gen-micro

Licence: other
Protobuf code generation

Programming Languages

go
31211 projects - #10 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to protoc-gen-micro

Protoc Gen Micro
Protobuf code generation for Micro. Moved to go-micro/cmd/protoc-gen-micro.
Stars: ✭ 270 (-5.92%)
Mutual labels:  protobuf, micro, go-micro
Go Os
Stars: ✭ 185 (-35.54%)
Mutual labels:  micro, go-micro
Micro Starter Kit
Cloud Native GoLang Microservices - gRPC, GraphQL
Stars: ✭ 167 (-41.81%)
Mutual labels:  micro, go-micro
Go Shopping
A sample suite of services built on the go-micro framework
Stars: ✭ 98 (-65.85%)
Mutual labels:  protobuf, go-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 (-76.66%)
Mutual labels:  micro, go-micro
Go Plugins
Go Micro Plugins. Moved to go-micro/plugins.
Stars: ✭ 1,654 (+476.31%)
Mutual labels:  micro, 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 (+85.37%)
Mutual labels:  protobuf, micro
MicroServicePractice
微服务实践的demo
Stars: ✭ 40 (-86.06%)
Mutual labels:  protobuf, go-micro
Wehousing
Golang微服务+区块链实战---go+micro+fabric实现租房上链系统
Stars: ✭ 182 (-36.59%)
Mutual labels:  protobuf, micro
Go Micro Boilerplate
The boilerplate of the GoLang application with a clear microservices architecture.
Stars: ✭ 147 (-48.78%)
Mutual labels:  protobuf, go-micro
Gomicro note
go-micro学习笔记
Stars: ✭ 62 (-78.4%)
Mutual labels:  micro, go-micro
RentHouseWeb
使用 go+docker+go-micro微服务框架开发的租房网系统,符合RESTful架构风格。
Stars: ✭ 28 (-90.24%)
Mutual labels:  protobuf, go-micro
Micro
go-micro 微服务实践,更多请关注Micro中国站☞
Stars: ✭ 383 (+33.45%)
Mutual labels:  micro, go-micro
Go Grpc
A simpler grpc framework
Stars: ✭ 133 (-53.66%)
Mutual labels:  micro, go-micro
Microservices
micro 微服务实例教程,包含JWT鉴权、熔断、监控、链路追踪、健康检查、跨域等
Stars: ✭ 341 (+18.82%)
Mutual labels:  micro, go-micro
Nano
Lightweight, facility, high performance golang based game server framework
Stars: ✭ 1,888 (+557.84%)
Mutual labels:  protobuf, micro
micro-starter
Micro 微服务实践
Stars: ✭ 391 (+36.24%)
Mutual labels:  micro, go-micro
micro-plugins
go-micro plugins, auth(JWT+Casbin)、go-micro服务加入istio服务网格
Stars: ✭ 27 (-90.59%)
Mutual labels:  micro, go-micro
CppSerialization
Performance comparison of the most popular C++ serialization protocols such as Cap'n'Proto, FastBinaryEncoding, Flatbuffers, Protobuf, JSON
Stars: ✭ 89 (-68.99%)
Mutual labels:  protobuf
typedash
🚀 2KB lodash in typescript
Stars: ✭ 26 (-90.94%)
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].