transport

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: May 28, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithValueTransporter

func WithValueTransporter(ctx context.Context, p Transporter) context.Context

WithValueTransporter returns a new Context that carries value.

Types

type ErrorTranslator

type ErrorTranslator interface {
	Translate(error) error
}
type Header interface {
	// Len returns the number of items in header.
	Len() int
	// Get returns the value associated with the passed key.
	Get(key string) string
	Set(key string, value string)
	// Add adds the key, value pair to the header.
	Add(key, value string)
	// Append adds the values to key k, not overwriting what was already stored at
	// that key.
	Append(key string, vals ...string)
	// Delete removes the values for a given key k which is converted to lowercase
	// before removing it from header.
	Delete(key string)
	Keys() []string
	Clone() Header
}

Header is the storage medium used by a Header.

type Kind

type Kind string

Kind defines the type of Transport

const (
	GRPC Kind = "grpc"
	HTTP Kind = "http"
)

Defines a set of transport kind

func (Kind) String

func (k Kind) String() string

type TranslatorData

type TranslatorData interface {
	TranslateData(v any) any
}

type TranslatorError

type TranslatorError interface {
	TranslateError(err error) (statusCode int, v any)
}

type Transporter

type Transporter interface {
	// Kind transporter
	// grpc
	// http
	Kind() Kind
	// FullPath Service full method or path
	FullPath() string
	// ClientIp client ip
	ClientIp() string
	// RequestHeader return transport request header
	// http: http.Header
	// grpc: metadata.MD
	RequestHeader() Header
	// ResponseHeader return transport response header
	// http: http.Header
	// grpc: metadata.MD
	ResponseHeader() Header
}

func FromTransporter

func FromTransporter(ctx context.Context) (p Transporter, ok bool)

FromTransporter returns the Transporter value stored in ctx, if any.

func MustFromTransporter

func MustFromTransporter(ctx context.Context) Transporter

MustFromTransporter returns the Transporter value stored in ctx.

Jump to

Keyboard shortcuts

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