gingrpc

package module
v0.0.0-...-7d4ba9c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2022 License: BSD-3-Clause Imports: 8 Imported by: 2

README

gin-grpc

The Gin middleware that forwards grpc requests

中文文档

  1. This middleware enables us to handle requests for different protocols simultaneously with just one piece of code

  2. Here is the Grpc middleware grpc-route

Usage Scenarios

  • Need to handle both Restful Api and Grpc

  • Network Framework and Business Framework (for example: MVC) are separated from each other, just need use the grpc way to write business, such as WebBFF and Services can use one Framework

  • Reuse Gin and Grpc community middleware to build your own Microservices framework (Customizable for Observability and Performance)

Benchmark

goos: windows
goarch: amd64
pkg: github.com/dan-and-dna/gin-grpc
cpu: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
BenchmarkGinGrpc
BenchmarkGinGrpc-12      3528080              1675 ns/op            1496 B/op
              13 allocs/op
PASS

Unit Test

=== RUN   TestGinGrpc
=== RUN   TestGinGrpc/TestJsonUnmarshalAndMarshal
=== RUN   TestGinGrpc/TestReturnNil
=== RUN   TestGinGrpc/TestRequestError
=== RUN   TestGinGrpc/TestRightRequest
=== RUN   TestGinGrpc/TestOmitempty
=== RUN   TestGinGrpc/TestBadBody
=== RUN   TestGinGrpc/TestEmptyBody
=== RUN   TestGinGrpc/TestBadPath
--- PASS: TestGinGrpc (0.00s)
    --- PASS: TestGinGrpc/TestJsonUnmarshalAndMarshal (0.00s)
    --- PASS: TestGinGrpc/TestReturnNil (0.00s)
    --- PASS: TestGinGrpc/TestRequestError (0.00s)
    --- PASS: TestGinGrpc/TestRightRequest (0.00s)
    --- PASS: TestGinGrpc/TestOmitempty (0.00s)
    --- PASS: TestGinGrpc/TestBadBody (0.00s)
    --- PASS: TestGinGrpc/TestEmptyBody (0.00s)
    --- PASS: TestGinGrpc/TestBadPath (0.00s)
PASS

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GinGrpc

func GinGrpc(option Option, httpHeader bool, grpcCtxOptions ...GrpcCtxOption) gin.HandlerFunc

Types

type GrpcCtxOption

type GrpcCtxOption interface {
	Apply(ctx context.Context) context.Context
}

type Handler

type Handler struct {
	Proto       proto.Message
	HandleProto func(context.Context, interface{}) (interface{}, error)
}

type Option

type Option interface {
	PathToGrpcService(c *gin.Context) string
	GetHandler(string) (*Handler, bool)
	SetHandler(string, *Handler)
}

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL