Documentation ¶
Index ¶
- Constants
- Variables
- func AppendRequestMetadataToContext(ctx context.Context, req *HTTPRequest) context.Context
- func Error(code int, msg string) error
- func ErrorFromHTTPResponse(resp *HTTPResponse) error
- func ErrorFromHTTPResponseWithMessage(resp *HTTPResponse, msg string) error
- func Errorf(code int, tmpl string, args ...interface{}) error
- func RegisterHTTPServer(s *grpc.Server, srv HTTPServer)
- func ToHTTPRequest(ctx context.Context, r *HTTPRequest) (*http.Request, error)
- func ToHeader(hs []*Header, header http.Header)
- func WriteError(w http.ResponseWriter, err error)
- func WriteResponse(w http.ResponseWriter, resp *HTTPResponse) error
- type HTTPClient
- type HTTPRequest
- func (*HTTPRequest) Descriptor() ([]byte, []int)
- func (this *HTTPRequest) Equal(that interface{}) bool
- func (m *HTTPRequest) GetBody() []byte
- func (m *HTTPRequest) GetHeaders() []*Header
- func (m *HTTPRequest) GetMethod() string
- func (m *HTTPRequest) GetUrl() string
- func (this *HTTPRequest) GoString() string
- func (m *HTTPRequest) Marshal() (dAtA []byte, err error)
- func (m *HTTPRequest) MarshalTo(dAtA []byte) (int, error)
- func (m *HTTPRequest) MarshalToSizedBuffer(dAtA []byte) (int, error)
- func (*HTTPRequest) ProtoMessage()
- func (m *HTTPRequest) Reset()
- func (m *HTTPRequest) Size() (n int)
- func (this *HTTPRequest) String() string
- func (m *HTTPRequest) Unmarshal(dAtA []byte) error
- func (m *HTTPRequest) XXX_DiscardUnknown()
- func (m *HTTPRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *HTTPRequest) XXX_Merge(src proto.Message)
- func (m *HTTPRequest) XXX_Size() int
- func (m *HTTPRequest) XXX_Unmarshal(b []byte) error
- type HTTPResponse
- func (*HTTPResponse) Descriptor() ([]byte, []int)
- func (this *HTTPResponse) Equal(that interface{}) bool
- func (m *HTTPResponse) GetBody() []byte
- func (m *HTTPResponse) GetCode() int32
- func (m *HTTPResponse) GetHeaders() []*Header
- func (this *HTTPResponse) GoString() string
- func (m *HTTPResponse) Marshal() (dAtA []byte, err error)
- func (m *HTTPResponse) MarshalTo(dAtA []byte) (int, error)
- func (m *HTTPResponse) MarshalToSizedBuffer(dAtA []byte) (int, error)
- func (*HTTPResponse) ProtoMessage()
- func (m *HTTPResponse) Reset()
- func (m *HTTPResponse) Size() (n int)
- func (this *HTTPResponse) String() string
- func (m *HTTPResponse) Unmarshal(dAtA []byte) error
- func (m *HTTPResponse) XXX_DiscardUnknown()
- func (m *HTTPResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *HTTPResponse) XXX_Merge(src proto.Message)
- func (m *HTTPResponse) XXX_Size() int
- func (m *HTTPResponse) XXX_Unmarshal(b []byte) error
- type HTTPServer
- type Header
- func (*Header) Descriptor() ([]byte, []int)
- func (this *Header) Equal(that interface{}) bool
- func (m *Header) GetKey() string
- func (m *Header) GetValues() []string
- func (this *Header) GoString() string
- func (m *Header) Marshal() (dAtA []byte, err error)
- func (m *Header) MarshalTo(dAtA []byte) (int, error)
- func (m *Header) MarshalToSizedBuffer(dAtA []byte) (int, error)
- func (*Header) ProtoMessage()
- func (m *Header) Reset()
- func (m *Header) Size() (n int)
- func (this *Header) String() string
- func (m *Header) Unmarshal(dAtA []byte) error
- func (m *Header) XXX_DiscardUnknown()
- func (m *Header) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *Header) XXX_Merge(src proto.Message)
- func (m *Header) XXX_Size() int
- func (m *Header) XXX_Unmarshal(b []byte) error
- type UnimplementedHTTPServer
Constants ¶
const ( MetadataMethod = "httpgrpc-method" MetadataURL = "httpgrpc-url" )
Variables ¶
var ( ErrInvalidLengthHttpgrpc = fmt.Errorf("proto: negative length found during unmarshaling") ErrIntOverflowHttpgrpc = fmt.Errorf("proto: integer overflow") )
Functions ¶
func AppendRequestMetadataToContext ¶
func AppendRequestMetadataToContext(ctx context.Context, req *HTTPRequest) context.Context
AppendRequestMetadataToContext appends metadata of HTTPRequest into gRPC metadata.
func Error ¶
Error returns a HTTP gRPC error that is correctly forwarded over gRPC, and can eventually be converted back to a HTTP response with HTTPResponseFromError.
func ErrorFromHTTPResponse ¶
func ErrorFromHTTPResponse(resp *HTTPResponse) error
ErrorFromHTTPResponse converts an HTTP response into a grpc error, and uses HTTP response body as an error message. Note that if HTTP response body contains non-utf8 string, then returned error cannot be marshalled by protobuf.
func ErrorFromHTTPResponseWithMessage ¶
func ErrorFromHTTPResponseWithMessage(resp *HTTPResponse, msg string) error
ErrorFromHTTPResponseWithMessage converts an HTTP response into a grpc error, and uses supplied message for Error message.
func Errorf ¶
Errorf returns a HTTP gRPC error that 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)
func ToHTTPRequest ¶
ToHTTPRequest converts httpgrpc.HTTPRequest to http.Request.
func WriteError ¶
func WriteError(w http.ResponseWriter, err error)
WriteError converts an httpgrpc error to an HTTP one
func WriteResponse ¶
func WriteResponse(w http.ResponseWriter, resp *HTTPResponse) error
WriteResponse converts an httpgrpc response to an HTTP one
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 FromHTTPRequest ¶
func FromHTTPRequest(r *http.Request) (*HTTPRequest, error)
FromHTTPRequest converts an ordinary http.Request into an httpgrpc.HTTPRequest
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) 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) 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 ¶
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 FromHeader ¶
func (*Header) Descriptor ¶
func (*Header) MarshalToSizedBuffer ¶
func (*Header) ProtoMessage ¶
func (*Header) ProtoMessage()
func (*Header) XXX_DiscardUnknown ¶
func (m *Header) XXX_DiscardUnknown()
func (*Header) XXX_Marshal ¶
func (*Header) XXX_Unmarshal ¶
type UnimplementedHTTPServer ¶
type UnimplementedHTTPServer struct { }
UnimplementedHTTPServer can be embedded to have forward compatible implementations.
func (*UnimplementedHTTPServer) Handle ¶
func (*UnimplementedHTTPServer) Handle(ctx context.Context, req *HTTPRequest) (*HTTPResponse, error)