Giter Club home page Giter Club logo

gorpc's Introduction

GoRPC Framework

GoRPC is a lightweight RPC framework, "Simple & Powerful".

GoRPC uses Google Protobuf as IDL (Interface Descriptor Language), it supports:

  • quickly generate server template, rpc server stub and rpc client stub
  • support multiple port and multiple protocols in the same process
  • support gorpc, http, and user customized business protocol
  • support tcp, udp, unix server and client
  • support naming service, default is etcd
  • support metrics, default is ouput to local stat file
  • support tracing, default is zipkin or jaeger
  • support logging, default is local logging

QuickStart

Taking following protofile as an example:

file: greeter.proto

syntax = "proto3";
package app;

option go_package = "github.com/examples/helloworld"
    
message Request {};
  
message Response {};
  
service greeter {
    rpc SayHello(Request)  returns(Response);
}

Run tool gorpc with subcmd generate to create template project:

gorpc generate -protocol=gorpc -protofile=greeter.proto -httpon

gorpc will create following project template:

greeter
  |- conf
      |- service.ini
  |- src
      |- main.go
      |- service
          |- service.go
          |- sayHello.go
      |- proto
          |- app
            |- greeter.proto
            |- greeter.pb.go

file: src/service/service.go

import "proto/app"

type service struct {}

func (s *service) SayHello(ctx context.Context, req app.Request) (rsp *app.Response, err error) {
	
	return
}

file: src/main.go

import (
	"gorpc/codec/gorpc"
	"gorpc/codec/http"
)


func main() {
    service := gorpc.NewService("gorpc/app.greeter").Version("1.0.0")
    service.Serve(&service.Service{})
}

file: conf/service.ini

[gorpc-service]
tcp.port = 10000
udp.port = 10000

[http-service]
http.port = 8080
http.prefix = /cgi-bin/service/

Build and test: make test, this will launch a process:

  • listen on 10000/tcp and 10001/udp, encoding/decoding via gorpc protocol
  • listen on 8080/tcp, encoding/decoding via http protocol
  • besides, you can define your business protocol, if needed.

This feature sometimes is very useful when you want to listen both tcp/udp port, or you want to expose some api interface via another protocol, for example, to be compatible with old protocol.

Maybe we will don't use it very often, but supporting multiple ports in one process is still a needed feature in mentioned cases. And this cases are indeed existed. So I decide to reserve this ability.

Efficient Developer Tools

tools function remark
gorpc quickly generate code
bot bot of qq, wework, slack
log logging analysis tool

Actually, gorpc is pluggable like go <subcmd> mechanism.

Go-RPC Arch Design

arch

Thanks

jetbrains.svg

Special thanks to the Jetbrains Team for their support.

gorpc's People

Contributors

hitzhangjie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

gorpc's Issues

Want to add customized template file in directory assets/

Is your feature request related to a problem? Please describe.
I want to add template files in directory assets, but gorpc doesn't handle it. The filelist to be handled in gorpc is hardcoded.

Describe the solution you'd like
gorpc can traverse every file in the template directory, and handles every file entry.

support import protofile

go template doesn't consider cases where external protofiles are imported.

the project of gorpc generated cannot be built correctly, some type references are wrong.

Please generate $service.rpc.go, put client server stub together

Is your feature request related to a problem? Please describe.
Now, gorpc generate client and server stub in two separate files, client.go and exec_....go, please put it into one file $service.gorpc.go.

Also, please using interface oriented manner, for example:
file: greeter.proto, package helloworld, service greeter

type GreeterServer interface {
    SayHello(......) (...)
    SayBye(......) (....)
}

type GreeterServerImpl struct {}

func (s *GreeterServerImpl) SayHello(...) (...) {}

type GreeterClient interface {
    SayHello(.......) (...)
    SayBye(.......) (....)
}

type GreeterClientImpl struct {}
func (c *Greeter......) SayHello(...) (...)

func NewClient(..............) GreeterClient {
     return GreeterClientImpl{....}
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.