Giter Club home page Giter Club logo

grpcext's Introduction

grpcext

grpcext is a Go package that provides extensions and utilities for working with gRPC.

Installation

To install grpcext, you can use the go get command:

go get github.com/poiati/grpcext

Usage

Here's an example of how to use the inspect.FieldsFor function to get the fields of a protocol buffer message:

fooReq := &proto.FooRequest{
    Text:               "fooValue",
    Number:             -32,
    Flag:               true,
    LongNumber:         -64,
    UnsignedNumber:     32,
    UnsignedLongNumber: 64,
}

fields := inspect.FieldsFor(fooReq)

fmt.Println(fields)

This will output the following:

[
    {"text", reflect.String, "fooValue"},
    {"number", reflect.Int32, int32(-32)},
    {"flag", reflect.Bool, true},
    {"long_number", reflect.Int64, int64(-64)},
    {"unsigned_number", reflect.Uint32, uint32(32)},
    {"unsigned_long_number", reflect.Uint64, uint64(64)},
]

You can find an example in the example folder of this repository. It uses this package for writting an interceptor that logs the grpc request and response.

$ go run example/main.go
time=2023-10-02T20:55:13.358-03:00 level=DEBUG msg="received GRPC Request" grpc.method=/proto.FooService/DoFoo grpc.req.text=foo grpc.req.number=11 grpc.req.flag=true
time=2023-10-02T20:55:13.358-03:00 level=INFO msg="Doing Foo!" grpc.method=/proto.FooService/DoFoo
time=2023-10-02T20:55:13.358-03:00 level=DEBUG msg="returning GRPC Response" grpc.method=/proto.FooService/DoFoo grpc.res.bar=bar!

Benchmark

There is a simple benchmark set to compare the perf. with and without the interceptor.

go test -bench=. ./example/ -benchmem -benchtime=10s
goos: linux
goarch: amd64
pkg: github.com/poiati/grpcext/example
cpu: AMD Ryzen 5 5600X 6-Core Processor
BenchmarkWithoutInterceptor/grpc_call-12                  108408            112382 ns/op            8934 B/op        175 allocs/op
BenchmarkWithIterceptor/grpc_call-12                      103459            115325 ns/op           11643 B/op        225 allocs/op
PASS
ok      github.com/poiati/grpcext/example       26.414s

Roadmap

For now it just supports basic fields inspection.

  • Add support to nested messages
  • Add support to lists (repeated)
  • Add support to maps
  • Add an option to exclude fields

grpcext's People

Contributors

poiati avatar

Stargazers

 avatar

Watchers

 avatar

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.