grpc

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2023 License: Apache-2.0 Imports: 17 Imported by: 3

Documentation

Index

Constants

View Source
const (
	TimeoutDefault = time.Second
	// Number of gRPC connection in a pool
	ConnPoolCount = 10
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Dispatcher

type Dispatcher struct {
	// contains filtered or unexported fields
}

func NewDispatcher

func NewDispatcher(config DispatcherConfig) (*Dispatcher, error)

NewDispatcher is the constructor to create a dispatcher. It will create the clientconn and set defaults. Endpoint, serviceMethod and response proto are required minimally to work.

func (*Dispatcher) Do

func (d *Dispatcher) Do(request fiber.Request) fiber.Response

type DispatcherConfig

type DispatcherConfig struct {
	ServiceMethod string
	Endpoint      string
	Timeout       time.Duration
}

type FiberCodec

type FiberCodec struct {
	// contains filtered or unexported fields
}

FiberCodec is a custom codec to prevent marshaling and unmarshalling when unnecessary, base on the inputs

func NewFiberCodec

func NewFiberCodec() *FiberCodec

func (*FiberCodec) Marshal

func (fc *FiberCodec) Marshal(v interface{}) ([]byte, error)

Marshal will attempt to pass the request directly if it is a byte slice, otherwise unmarshal the request proto using the default implementation

func (*FiberCodec) Name

func (*FiberCodec) Name() string

func (*FiberCodec) Unmarshal

func (fc *FiberCodec) Unmarshal(data []byte, v interface{}) error

Unmarshal will attempt to write the request directly if it is a writer, otherwise unmarshal the request proto using the default implementation

type Request

type Request struct {
	// Metadata will hold the grpc headers for request
	Metadata metadata.MD
	Message  []byte
	Proto    proto.Message
}

func NewRequest

func NewRequest(metadata metadata.MD, msg []byte, protoMsg proto.Message) *Request

func (*Request) Clone

func (r *Request) Clone() (fiber.Request, error)

func (*Request) Header

func (r *Request) Header() map[string][]string

func (*Request) OperationName

func (r *Request) OperationName() string

OperationName is naming used in tracing interceptors

func (*Request) Payload

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

func (*Request) ProtoMessage

func (r *Request) ProtoMessage() proto.Message

func (*Request) Protocol

func (r *Request) Protocol() protocol.Protocol

func (*Request) Transform

func (r *Request) Transform(_ fiber.Backend) (fiber.Request, error)

Transform is use by backend component within a Proxy to abstract endpoint from dispatcher

type Response

type Response struct {
	Metadata metadata.MD
	Message  []byte
	Status   status.Status
}

func (*Response) BackendName

func (r *Response) BackendName() string

func (*Response) IsSuccess

func (r *Response) IsSuccess() bool

func (*Response) Label

func (r *Response) Label(key string) []string

Label returns all the values associated with the given key, in the response metadata. If the key does not exist, an empty slice will be returned.

func (*Response) Payload

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

func (*Response) StatusCode

func (r *Response) StatusCode() int

func (*Response) WithBackendName

func (r *Response) WithBackendName(backendName string) fiber.Response

WithBackendName sets the given backend name in the response metadata. The modified response is returned.

func (*Response) WithLabel

func (r *Response) WithLabel(key string, values ...string) fiber.Response

WithLabel appends the given value(s) to the key, in the response metadata. If the key does not already exist, a new key will be created. The modified response is returned.

func (*Response) WithLabels

func (r *Response) WithLabels(labels fiber.Labels) fiber.Response

WithLabels does the same thing as WithLabel but over a collection of key-values.

Jump to

Keyboard shortcuts

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