httpgrpc

package
v0.0.0-...-d74ee84 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2020 License: Apache-2.0 Imports: 16 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/gogo/protobuf

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidLengthHttpgrpc        = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowHttpgrpc          = fmt.Errorf("proto: integer overflow")
	ErrUnexpectedEndOfGroupHttpgrpc = fmt.Errorf("proto: unexpected end of group")
)

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)
}

HTTPClient is the client API for HTTP service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.

func NewHTTPClient

func NewHTTPClient(cc *grpc.ClientConn) HTTPClient

type HTTPRequest

type HTTPRequest struct {
	Method  string    `protobuf:"bytes,1,opt,name=method,proto3" json:"method,omitempty"`
	Url     string    `protobuf:"bytes,2,opt,name=url,proto3" json:"url,omitempty"`
	Headers []*Header `protobuf:"bytes,3,rep,name=headers,proto3" 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) Equal

func (this *HTTPRequest) Equal(that interface{}) bool

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) GoString

func (this *HTTPRequest) GoString() string

func (*HTTPRequest) Marshal

func (m *HTTPRequest) Marshal() (dAtA []byte, err error)

func (*HTTPRequest) MarshalTo

func (m *HTTPRequest) MarshalTo(dAtA []byte) (int, error)

func (*HTTPRequest) MarshalToSizedBuffer

func (m *HTTPRequest) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*HTTPRequest) ProtoMessage

func (*HTTPRequest) ProtoMessage()

func (*HTTPRequest) Reset

func (m *HTTPRequest) Reset()

func (*HTTPRequest) Size

func (m *HTTPRequest) Size() (n int)

func (*HTTPRequest) String

func (this *HTTPRequest) String() string

func (*HTTPRequest) Unmarshal

func (m *HTTPRequest) Unmarshal(dAtA []byte) error

func (*HTTPRequest) XXX_DiscardUnknown

func (m *HTTPRequest) XXX_DiscardUnknown()

func (*HTTPRequest) XXX_Marshal

func (m *HTTPRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*HTTPRequest) XXX_Merge

func (m *HTTPRequest) XXX_Merge(src proto.Message)

func (*HTTPRequest) XXX_Size

func (m *HTTPRequest) XXX_Size() int

func (*HTTPRequest) XXX_Unmarshal

func (m *HTTPRequest) XXX_Unmarshal(b []byte) error

type HTTPResponse

type HTTPResponse struct {
	Code    int32     `protobuf:"varint,1,opt,name=Code,proto3" json:"Code,omitempty"`
	Headers []*Header `protobuf:"bytes,2,rep,name=headers,proto3" 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) Equal

func (this *HTTPResponse) Equal(that interface{}) bool

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) GoString

func (this *HTTPResponse) GoString() string

func (*HTTPResponse) Marshal

func (m *HTTPResponse) Marshal() (dAtA []byte, err error)

func (*HTTPResponse) MarshalTo

func (m *HTTPResponse) MarshalTo(dAtA []byte) (int, error)

func (*HTTPResponse) MarshalToSizedBuffer

func (m *HTTPResponse) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*HTTPResponse) ProtoMessage

func (*HTTPResponse) ProtoMessage()

func (*HTTPResponse) Reset

func (m *HTTPResponse) Reset()

func (*HTTPResponse) Size

func (m *HTTPResponse) Size() (n int)

func (*HTTPResponse) String

func (this *HTTPResponse) String() string

func (*HTTPResponse) Unmarshal

func (m *HTTPResponse) Unmarshal(dAtA []byte) error

func (*HTTPResponse) XXX_DiscardUnknown

func (m *HTTPResponse) XXX_DiscardUnknown()

func (*HTTPResponse) XXX_Marshal

func (m *HTTPResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*HTTPResponse) XXX_Merge

func (m *HTTPResponse) XXX_Merge(src proto.Message)

func (*HTTPResponse) XXX_Size

func (m *HTTPResponse) XXX_Size() int

func (*HTTPResponse) XXX_Unmarshal

func (m *HTTPResponse) XXX_Unmarshal(b []byte) error

type HTTPServer

type HTTPServer interface {
	Handle(context.Context, *HTTPRequest) (*HTTPResponse, error)
}

HTTPServer is the server API for HTTP service.

type Header struct {
	Key    string   `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
	Values []string `protobuf:"bytes,2,rep,name=values,proto3" json:"values,omitempty"`
}

func (*Header) Descriptor

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

func (*Header) Equal

func (this *Header) Equal(that interface{}) bool

func (*Header) GetKey

func (m *Header) GetKey() string

func (*Header) GetValues

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

func (*Header) GoString

func (this *Header) GoString() string

func (*Header) Marshal

func (m *Header) Marshal() (dAtA []byte, err error)

func (*Header) MarshalTo

func (m *Header) MarshalTo(dAtA []byte) (int, error)

func (*Header) MarshalToSizedBuffer

func (m *Header) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*Header) ProtoMessage

func (*Header) ProtoMessage()

func (*Header) Reset

func (m *Header) Reset()

func (*Header) Size

func (m *Header) Size() (n int)

func (*Header) String

func (this *Header) String() string

func (*Header) Unmarshal

func (m *Header) Unmarshal(dAtA []byte) error

func (*Header) XXX_DiscardUnknown

func (m *Header) XXX_DiscardUnknown()

func (*Header) XXX_Marshal

func (m *Header) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Header) XXX_Merge

func (m *Header) XXX_Merge(src proto.Message)

func (*Header) XXX_Size

func (m *Header) XXX_Size() int

func (*Header) XXX_Unmarshal

func (m *Header) XXX_Unmarshal(b []byte) error

type UnimplementedHTTPServer

type UnimplementedHTTPServer struct {
}

UnimplementedHTTPServer can be embedded to have forward compatible implementations.

func (*UnimplementedHTTPServer) Handle

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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