Coder Social home page Coder Social logo

go-grpc-net-conn's Introduction

go-grpc-net-conn Godoc

go-grpc-net-conn is a Go library that creates a net.Conn implementation on top of gRPC streams. If the stream is bidirectional (both the request and response of an RPC is a stream) then the net.Conn is a full-duplex connection.

Installation

Standard go get:

$ go get github.com/mitchellh/go-grpc-net-conn

Usage & Example

For usage and examples see the Godoc.

A brief example is shown below. Note that the only minor complexity is populating the required fields for the Conn structure. This package needs to know how to encode and decode the byte slices onto your expected protobuf message types.

Imagine a protobuf service that looks like the following:

syntax = "proto3";

package example;

service ExampleService {
  rpc Stream(stream Bytes) returns (stream Bytes);
}

message Bytes {
  bytes data = 1;
}

You can use this in the following way:

// Call our streaming endpoint
resp, err := client.Stream(context.Background())

// We need to create a callback so the conn knows how to decode/encode
// arbitrary byte slices for our proto type.
fieldFunc := func(msg proto.Message) *[]byte {
	return &msg.(*example.Bytes).Data
}

// Wrap our conn around the response.
conn := &grpc_net_conn.Conn{
	Stream: resp,
	Request: &example.Bytes{},
	Response: &example.Bytes{},
	Encode: SimpleEncoder(fieldFunc),
	Decode: SimpleDecoder(fieldFunc),
}

// conn implements net.Conn so use it as you would!

go-grpc-net-conn's People

Contributors

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