grpcprot

package
v2.7.3 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package grpcprot implements the grpc protocol.

Index

Constants

View Source
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.

func (*Addr) Network

func (a *Addr) Network() string

Network returns the network type of the address.

func (*Addr) String

func (a *Addr) String() string

String implements the Stringer interface.

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 struct {
	// contains filtered or unexported fields
}

Header wrapper metadata.MD

func NewHeader

func NewHeader(md metadata.MD) *Header

NewHeader returns a new Header

func (*Header) Add

func (h *Header) Add(key string, value interface{})

Add adds the key, value pair to the header.

func (*Header) Clone

func (h *Header) Clone() protocols.Header

Clone returns a copy of the header.

func (*Header) Del

func (h *Header) Del(key string)

Del deletes the values associated with key.

func (*Header) Get

func (h *Header) Get(key string) interface{}

Get gets the values associated with the given key.

func (*Header) GetFirst

func (h *Header) GetFirst(k string) string

GetFirst returns the first value for a given key. k is converted to lowercase before searching in md.

func (*Header) GetMD

func (h *Header) GetMD() metadata.MD

GetMD returns the metadata.MD

func (*Header) Merge

func (h *Header) Merge(header *Header)

Merge all the provided metadata will be merged

func (*Header) RawAdd

func (h *Header) RawAdd(key string, values ...string)

RawAdd adds the key, value pair to the header.

func (*Header) RawGet

func (h *Header) RawGet(key string) []string

RawGet gets the values associated with the given key.

func (*Header) RawSet

func (h *Header) RawSet(key string, values ...string)

RawSet sets the header entries associated with key to the given value.

func (*Header) Set

func (h *Header) Set(key string, value interface{})

Set sets the header entries associated with key to the given value.

func (*Header) Walk

func (h *Header) Walk(fn func(key string, value interface{}) bool)

Walk for each key exec fn()

type Protocol

type Protocol struct {
}

Protocol implements protocols.Protocol for HTTP.

func (*Protocol) BuildRequest

func (p *Protocol) BuildRequest(reqInfo interface{}) (protocols.Request, error)

BuildRequest builds a Request from request info.

func (*Protocol) BuildResponse

func (p *Protocol) BuildResponse(respInfo interface{}) (protocols.Response, error)

BuildResponse builds a Response from response info.

func (*Protocol) CreateRequest

func (p *Protocol) CreateRequest(req interface{}) (protocols.Request, error)

CreateRequest creates a Request.

func (*Protocol) CreateResponse

func (p *Protocol) CreateResponse(resp interface{}) (protocols.Response, error)

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

func NewRequestWithContext(ctx context.Context) *Request

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

func (r *Request) Close()

Close returns the request

func (*Request) Context

func (r *Request) Context() context.Context

Context returns the context of the request

func (*Request) FullMethod

func (r *Request) FullMethod() string

FullMethod returns full method name of the grpc request. The returned string is in the format of "/service/method"

func (*Request) GetPayload

func (r *Request) GetPayload() io.Reader

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

func (r *Request) Header() protocols.Header

Header returns the header of the request in type protocols.Header.

func (*Request) Host

func (r *Request) Host() string

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

func (r *Request) IsStream() bool

IsStream returns whether the payload of the request is a stream.

func (*Request) Method

func (r *Request) Method() string

Method returns method name of the grpc request.

func (*Request) OnlyHost

func (r *Request) OnlyHost() string

OnlyHost return host or hostname without port

func (*Request) PayloadSize

func (r *Request) PayloadSize() int64

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

func (r *Request) RawHeader() *Header

RawHeader returns the header of the request in type metadata.MD.

func (*Request) RawPayload

func (r *Request) RawPayload() []byte

RawPayload returns the payload in []byte, the caller should not modify its content. The function panic if the payload is a stream.

func (*Request) RealIP

func (r *Request) RealIP() string

RealIP return the client ip from peer.FromContext()

func (*Request) Service

func (r *Request) Service() string

Service returns service name of the grpc request.

func (*Request) SetFullMethod

func (r *Request) SetFullMethod(path string)

SetFullMethod sets full method name of the grpc request.

func (*Request) SetHeader

func (r *Request) SetHeader(header *Header)

SetHeader use md set Request.header

func (*Request) SetHost

func (r *Request) SetHost(host string)

SetHost set the host of the 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) SetRealIP

func (r *Request) SetRealIP(ip string)

SetRealIP set the client ip of the request.

func (*Request) SetSourceHost

func (r *Request) SetSourceHost(sourceHost string)

SetSourceHost set the source host of the request.

func (*Request) SourceHost

func (r *Request) SourceHost() string

SourceHost returns peer host from grpc context

func (*Request) ToBuilderRequest

func (r *Request) ToBuilderRequest(name string) interface{}

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 NewResponse

func NewResponse() *Response

NewResponse returns a new Response.

func (*Response) Close

func (r *Response) Close()

Close closes the response.

func (*Response) GetPayload

func (r *Response) GetPayload() io.Reader

GetPayload returns the payload of the response.

func (*Response) GetStatus

func (r *Response) GetStatus() *status.Status

GetStatus returns the status of the response.

func (*Response) Header

func (r *Response) Header() protocols.Header

Header returns the header of the response.

func (*Response) IsStream

func (r *Response) IsStream() bool

IsStream returns true if the response is a stream.

func (*Response) PayloadSize

func (r *Response) PayloadSize() int64

PayloadSize returns the size of the payload.

func (*Response) RawHeader

func (r *Response) RawHeader() *Header

RawHeader returns the header of the request in type metadata.MD.

func (*Response) RawPayload

func (r *Response) RawPayload() []byte

RawPayload returns the payload of the response.

func (*Response) RawTrailer

func (r *Response) RawTrailer() *Trailer

RawTrailer returns the trailer of the response.

func (*Response) SetHeader

func (r *Response) SetHeader(header *Header)

SetHeader sets the header of the response.

func (*Response) SetPayload

func (r *Response) SetPayload(payload interface{})

SetPayload sets the payload of the response.

func (*Response) SetStatus

func (r *Response) SetStatus(s *status.Status)

SetStatus sets the status of the response.

func (*Response) SetTrailer

func (r *Response) SetTrailer(trailer *Trailer)

SetTrailer sets the trailer of the response.

func (*Response) StatusCode

func (r *Response) StatusCode() int

StatusCode returns the status code of the response.

func (*Response) ToBuilderResponse

func (r *Response) ToBuilderResponse(name string) interface{}

ToBuilderResponse wraps the response and returns the wrapper, the return value can be used in the template of the Builder filters.

func (*Response) Trailer

func (r *Response) Trailer() protocols.Trailer

Trailer returns the trailer of the response.

type Trailer

type Trailer = Header

Trailer wrapper metadata.MD. used for grpc response in server-side

func NewTrailer

func NewTrailer(md metadata.MD) *Trailer

NewTrailer returns a new Trailer

Jump to

Keyboard shortcuts

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