Documentation ¶
Overview ¶
Package grpcprot implements the grpc protocol.
Index ¶
- Constants
- type Addr
- type FakeServerStream
- type Header
- func (h *Header) Add(key string, value interface{})
- func (h *Header) Clone() protocols.Header
- func (h *Header) Del(key string)
- func (h *Header) Get(key string) interface{}
- func (h *Header) GetFirst(k string) string
- func (h *Header) GetMD() metadata.MD
- func (h *Header) Merge(header *Header)
- func (h *Header) RawAdd(key string, values ...string)
- func (h *Header) RawGet(key string) []string
- func (h *Header) RawSet(key string, values ...string)
- func (h *Header) Set(key string, value interface{})
- func (h *Header) Walk(fn func(key string, value interface{}) bool)
- type Protocol
- func (p *Protocol) BuildRequest(reqInfo interface{}) (protocols.Request, error)
- func (p *Protocol) BuildResponse(respInfo interface{}) (protocols.Response, error)
- func (p *Protocol) CreateRequest(req interface{}) (protocols.Request, error)
- func (p *Protocol) CreateResponse(resp interface{}) (protocols.Response, error)
- func (p *Protocol) NewRequestInfo() interface{}
- func (p *Protocol) NewResponseInfo() interface{}
- type Request
- func (r *Request) Close()
- func (r *Request) Context() context.Context
- func (r *Request) FullMethod() string
- func (r *Request) GetPayload() io.Reader
- func (r *Request) GetServerStream() grpc.ServerStream
- func (r *Request) Header() protocols.Header
- func (r *Request) Host() string
- func (r *Request) IsStream() bool
- func (r *Request) Method() string
- func (r *Request) OnlyHost() string
- func (r *Request) PayloadSize() int64
- func (r *Request) RawHeader() *Header
- func (r *Request) RawPayload() []byte
- func (r *Request) RealIP() string
- func (r *Request) Service() string
- func (r *Request) SetFullMethod(path string)
- func (r *Request) SetHeader(header *Header)
- func (r *Request) SetHost(host string)
- func (r *Request) SetPayload(payload interface{})
- func (r *Request) SetRealIP(ip string)
- func (r *Request) SetSourceHost(sourceHost string)
- func (r *Request) SourceHost() string
- func (r *Request) ToBuilderRequest(name string) interface{}
- type Response
- func (r *Response) Close()
- func (r *Response) GetPayload() io.Reader
- func (r *Response) GetStatus() *status.Status
- func (r *Response) Header() protocols.Header
- func (r *Response) IsStream() bool
- func (r *Response) PayloadSize() int64
- func (r *Response) RawHeader() *Header
- func (r *Response) RawPayload() []byte
- func (r *Response) RawTrailer() *Trailer
- func (r *Response) SetHeader(header *Header)
- func (r *Response) SetPayload(payload interface{})
- func (r *Response) SetStatus(s *status.Status)
- func (r *Response) SetTrailer(trailer *Trailer)
- func (r *Response) StatusCode() int
- func (r *Response) ToBuilderResponse(name string) interface{}
- func (r *Response) Trailer() protocols.Trailer
- type Trailer
Constants ¶
const (
// Authority is the key of authority in grpc metadata
Authority = ":authority"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Addr ¶
type Addr struct {
// contains filtered or unexported fields
}
Addr is a net.Addr backed by either a TCP "ip:port" string, or the empty string if unknown.
type FakeServerStream ¶
type FakeServerStream struct { grpc.ServerStream // contains filtered or unexported fields }
FakeServerStream is a fake grpc.ServerStream for testing.
func NewFakeServerStream ¶
func NewFakeServerStream(ctx context.Context) *FakeServerStream
NewFakeServerStream returns a new FakeServerStream.
func (*FakeServerStream) Context ¶
func (f *FakeServerStream) Context() context.Context
Context returns the context of the stream.
func (*FakeServerStream) SetTrailer ¶
func (f *FakeServerStream) SetTrailer(md metadata.MD)
type Header ¶
type Header struct {
// contains filtered or unexported fields
}
Header wrapper metadata.MD
func (*Header) GetFirst ¶
GetFirst returns the first value for a given key. k is converted to lowercase before searching in md.
type Protocol ¶
type Protocol struct { }
Protocol implements protocols.Protocol for HTTP.
func (*Protocol) BuildRequest ¶
BuildRequest builds a Request from request info.
func (*Protocol) BuildResponse ¶
BuildResponse builds a Response from response info.
func (*Protocol) CreateRequest ¶
CreateRequest creates a Request.
func (*Protocol) CreateResponse ¶
CreateResponse creates a Response.
func (*Protocol) NewRequestInfo ¶
func (p *Protocol) NewRequestInfo() interface{}
NewRequestInfo creates a RequestInfo.
func (*Protocol) NewResponseInfo ¶
func (p *Protocol) NewResponseInfo() interface{}
NewResponseInfo creates a ResponseInfo.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request wraps grpc.ServerStream,based on the following considerations: 1.in the case of replication, the dst object should be consistent with the source object, so all modifications should be written directly into source object's ctx 2.the atomicity of header.
func NewRequestWithContext ¶
NewRequestWithContext creates a new request from context. that only have request data, not support reply to client
func NewRequestWithServerStream ¶
func NewRequestWithServerStream(stream grpc.ServerStream) *Request
NewRequestWithServerStream creates a new request from a grpc.ServerStream that have data and conn, so it could reply to client with data
func (*Request) FullMethod ¶
FullMethod returns full method name of the grpc request. The returned string is in the format of "/service/method"
func (*Request) GetPayload ¶
GetPayload returns a payload reader. For non-stream payload, the returned reader is always a new one, which contains the full data. For stream payload, the function always returns the same reader.
func (*Request) GetServerStream ¶
func (r *Request) GetServerStream() grpc.ServerStream
GetServerStream return the underlying grpc.ServerStream
func (*Request) Host ¶
Host refer to google.golang.org\grpc@v1.46.2\internal\transport\http2_server.go#operateHeaders It may be of the form "host:port" or contain an international domain name.
func (*Request) PayloadSize ¶
PayloadSize returns the size of the payload. If the payload is a stream, it returns the bytes count that have been currently read out.
func (*Request) RawPayload ¶
RawPayload returns the payload in []byte, the caller should not modify its content. The function panic if the payload is a stream.
func (*Request) SetFullMethod ¶
SetFullMethod sets full method name of the grpc request.
func (*Request) SetPayload ¶
func (r *Request) SetPayload(payload interface{})
SetPayload set the payload of the response to payload. The payload could be a string, a byte slice, or an io.Reader, and if it is an io.Reader, it will be treated as a stream, if this is not desired, please read the data to a byte slice, and set the byte slice as the payload.
func (*Request) SetSourceHost ¶
SetSourceHost set the source host of the request.
func (*Request) SourceHost ¶
SourceHost returns peer host from grpc context
func (*Request) ToBuilderRequest ¶
ToBuilderRequest wraps the request and returns the wrapper, the return value can be used in the template of the Builder filters.
type Response ¶
type Response struct { // instead status.Status // nil or from codes.OK means success, otherwise means fail *status.Status // contains filtered or unexported fields }
Response wrapper status.Status
func (*Response) GetPayload ¶
GetPayload returns the payload of the response.
func (*Response) PayloadSize ¶
PayloadSize returns the size of the payload.
func (*Response) RawPayload ¶
RawPayload returns the payload of the response.
func (*Response) RawTrailer ¶
RawTrailer returns the trailer of the response.
func (*Response) SetPayload ¶
func (r *Response) SetPayload(payload interface{})
SetPayload sets the payload of the response.
func (*Response) SetTrailer ¶
SetTrailer sets the trailer of the response.
func (*Response) StatusCode ¶
StatusCode returns the status code of the response.
func (*Response) ToBuilderResponse ¶
ToBuilderResponse wraps the response and returns the wrapper, the return value can be used in the template of the Builder filters.