Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

  • v0.0.0-20200427190222-eb030e4876f0
  • Source
  • Go
  • Socket score

Version published
Created
Source

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!

FAQs

Package last updated on 27 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc