httpgrpc

package
v0.0.0-...-ebab3a7 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2018 License: Apache-2.0 Imports: 10 Imported by: 0

README

What? Embedding HTTP requests and responses into a gRPC service; a service and client to translate back and forth between the two, so you can use them with your faviourite mux.

Why? Get all the goodness of protobuf encoding, HTTP/2, snappy, load balancing, persistent connection and native Kuberneretes load balancing with ~none of the effort.

To rebuild generated protobuf code, run:

protoc -I ./ --go_out=plugins=grpc:./ ./httpgrpc.proto

Follow the instructions here to get a working protoc: https://github.com/golang/protobuf

Documentation

Overview

Package httpgrpc is a generated protocol buffer package.

It is generated from these files:

github.com/weaveworks/common/httpgrpc/httpgrpc.proto

It has these top-level messages:

HTTPRequest
HTTPResponse
Header

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorFromHTTPResponse

func ErrorFromHTTPResponse(resp *HTTPResponse) error

ErrorFromHTTPResponse converts an HTTP response into a grpc error

func Errorf

func Errorf(code int, tmpl string, args ...interface{}) error

Errorf returns a HTTP gRPC error than is correctly forwarded over gRPC, and can eventually be converted back to a HTTP response with HTTPResponseFromError.

func RegisterHTTPServer

func RegisterHTTPServer(s *grpc.Server, srv HTTPServer)

Types

type HTTPClient

type HTTPClient interface {
	Handle(ctx context.Context, in *HTTPRequest, opts ...grpc.CallOption) (*HTTPResponse, error)
}

func NewHTTPClient

func NewHTTPClient(cc *grpc.ClientConn) HTTPClient

type HTTPRequest

type HTTPRequest struct {
	Method  string    `protobuf:"bytes,1,opt,name=method" json:"method,omitempty"`
	Url     string    `protobuf:"bytes,2,opt,name=url" json:"url,omitempty"`
	Headers []*Header `protobuf:"bytes,3,rep,name=headers" json:"headers,omitempty"`
	Body    []byte    `protobuf:"bytes,4,opt,name=body,proto3" json:"body,omitempty"`
}

func (*HTTPRequest) Descriptor

func (*HTTPRequest) Descriptor() ([]byte, []int)

func (*HTTPRequest) GetBody

func (m *HTTPRequest) GetBody() []byte

func (*HTTPRequest) GetHeaders

func (m *HTTPRequest) GetHeaders() []*Header

func (*HTTPRequest) GetMethod

func (m *HTTPRequest) GetMethod() string

func (*HTTPRequest) GetUrl

func (m *HTTPRequest) GetUrl() string

func (*HTTPRequest) ProtoMessage

func (*HTTPRequest) ProtoMessage()

func (*HTTPRequest) Reset

func (m *HTTPRequest) Reset()

func (*HTTPRequest) String

func (m *HTTPRequest) String() string

type HTTPResponse

type HTTPResponse struct {
	Code    int32     `protobuf:"varint,1,opt,name=Code" json:"Code,omitempty"`
	Headers []*Header `protobuf:"bytes,2,rep,name=headers" json:"headers,omitempty"`
	Body    []byte    `protobuf:"bytes,3,opt,name=body,proto3" json:"body,omitempty"`
}

func HTTPResponseFromError

func HTTPResponseFromError(err error) (*HTTPResponse, bool)

HTTPResponseFromError converts a grpc error into an HTTP response

func (*HTTPResponse) Descriptor

func (*HTTPResponse) Descriptor() ([]byte, []int)

func (*HTTPResponse) GetBody

func (m *HTTPResponse) GetBody() []byte

func (*HTTPResponse) GetCode

func (m *HTTPResponse) GetCode() int32

func (*HTTPResponse) GetHeaders

func (m *HTTPResponse) GetHeaders() []*Header

func (*HTTPResponse) ProtoMessage

func (*HTTPResponse) ProtoMessage()

func (*HTTPResponse) Reset

func (m *HTTPResponse) Reset()

func (*HTTPResponse) String

func (m *HTTPResponse) String() string

type HTTPServer

type HTTPServer interface {
	Handle(context.Context, *HTTPRequest) (*HTTPResponse, error)
}
type Header struct {
	Key    string   `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
	Values []string `protobuf:"bytes,2,rep,name=values" json:"values,omitempty"`
}

func (*Header) Descriptor

func (*Header) Descriptor() ([]byte, []int)

func (*Header) GetKey

func (m *Header) GetKey() string

func (*Header) GetValues

func (m *Header) GetValues() []string

func (*Header) ProtoMessage

func (*Header) ProtoMessage()

func (*Header) Reset

func (m *Header) Reset()

func (*Header) String

func (m *Header) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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