transports

package
v1.2.85 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2024 License: Apache-2.0 Imports: 25 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ContentTypeHeaderName                        = []byte("Content-Type")
	ContentTypeJsonHeaderValue                   = []byte("application/json")
	ContentTypeTextHeaderValue                   = []byte("text/plain")
	ContentTypeAvroHeaderValue                   = []byte("application/avro")
	ContentLengthHeaderName                      = []byte("Content-Length")
	AuthorizationHeaderName                      = []byte("Authorization")
	CookieHeaderName                             = []byte("Cookie")
	ConnectionHeaderName                         = []byte("Connection")
	UpgradeHeaderName                            = []byte("Upgrade")
	CloseHeaderValue                             = []byte("close")
	AcceptEncodingHeaderName                     = []byte("Accept-Encoding")
	ContentEncodingHeaderName                    = []byte("Content-Encoding")
	ClearSiteDataHeaderName                      = []byte("Clear-Site-Data")
	CacheControlHeaderName                       = []byte("Cache-Control")
	AgeHeaderName                                = []byte("Age")
	CacheControlHeaderNoStore                    = []byte("no-store")
	CacheControlHeaderNoCache                    = []byte("no-cache")
	ETagHeaderName                               = []byte("ETag")
	CacheControlHeaderIfNonMatch                 = []byte("If-None-Match")
	VaryHeaderName                               = []byte("Vary")
	OriginHeaderName                             = []byte("Origin")
	AcceptHeaderName                             = []byte("Accept")
	AccessControlRequestMethodHeaderName         = []byte("Access-Control-Request-Method")
	AccessControlRequestHeadersHeaderName        = []byte("Access-Control-Request-Headers")
	AccessControlRequestPrivateNetworkHeaderName = []byte("Access-Control-Request-Private-Network")
	AccessControlAllowOriginHeaderName           = []byte("Access-Control-Allow-Origin")
	AccessControlAllowMethodsHeaderName          = []byte("Access-Control-Allow-Methods")
	AccessControlAllowHeadersHeaderName          = []byte("Access-Control-Allow-Headers")
	AccessControlAllowCredentialsHeaderName      = []byte("Access-Control-Allow-Credentials")
	AccessControlAllowPrivateNetworkHeaderName   = []byte("Access-Control-Allow-Private-Network")
	AccessControlMaxAgeHeaderName                = []byte("Access-Control-Max-Age")
	AccessControlExposeHeadersHeaderName         = []byte("Access-Control-Expose-Headers")
	XRequestedWithHeaderName                     = []byte("X-Requested-With")
	TrueClientIpHeaderName                       = []byte("True-Client-Ip")
	XRealIpHeaderName                            = []byte("X-Real-IP")
	XForwardedForHeaderName                      = []byte("X-Forwarded-For")
	RequestIdHeaderName                          = []byte("X-Fns-Request-Id")
	SignatureHeaderName                          = []byte("X-Fns-Signature")
	EndpointIdHeaderName                         = []byte("X-Fns-Endpoint-Id")
	EndpointVersionHeaderName                    = []byte("X-Fns-Endpoint-Version")
	RequestTimeoutHeaderName                     = []byte("X-Fns-Request-Timeout")
	RequestVersionsHeaderName                    = []byte("X-Fns-Request-Version")
	HandleLatencyHeaderName                      = []byte("X-Fns-Handle-Latency")
	DeviceIdHeaderName                           = []byte("X-Fns-Device-Id")
	DeviceIpHeaderName                           = []byte("X-Fns-Device-Ip")
	DeprecatedHeaderName                         = []byte("X-Fns-Deprecated")
	ResponseRetryAfterHeaderName                 = []byte("Retry-After")
	UserHeaderNamePrefix                         = []byte("XU-")
)
View Source
var (
	MethodGet  = []byte(http.MethodGet)
	MethodPost = []byte(http.MethodPost)
)
View Source
var (
	ErrTooBigRequestBody = errors.New(http.StatusRequestEntityTooLarge, "***TOO LARGE BODY***", "fns: request body is too large")
)

Functions

func AddXU added in v1.2.32

func AddXU(header Header, name []byte, value []byte)

func DecodeParams

func DecodeParams(params Params, dst interface{}) (err error)

func DeviceIp

func DeviceIp(ctx context.Context) (ip []byte)

func GetXU added in v1.2.32

func GetXU(header Header, name []byte) (value []byte)

func ObjectParams added in v1.2.0

func ObjectParams(params Params) objects.Object

func ReleaseCookie

func ReleaseCookie(c *Cookie)

func ReleaseHeader

func ReleaseHeader(h Header)

func ReleaseResultResponseWriter

func ReleaseResultResponseWriter(w *ResultResponseWriter)

func SetXU added in v1.2.32

func SetXU(header Header, name []byte, value []byte)

func ValuesXU added in v1.2.32

func ValuesXU(header Header, name []byte) (value [][]byte)

func WithRequest

func WithRequest(ctx context.Context, r Request) context.Context

func WithRequestHeader added in v1.1.3

func WithRequestHeader(ctx context.Context, header Header) context.Context

func WithResponse

func WithResponse(ctx context.Context, w ResponseWriter) context.Context

Types

type AcceptEncoding added in v1.2.12

type AcceptEncoding struct {
	Name    []byte
	Quality float64
}

type AcceptEncodings added in v1.2.12

type AcceptEncodings []AcceptEncoding

func GetAcceptEncodings added in v1.2.12

func GetAcceptEncodings(header Header) (encodings AcceptEncodings)

func (AcceptEncodings) Add added in v1.2.21

func (encodings AcceptEncodings) Add(name []byte, quality float64) AcceptEncodings

func (AcceptEncodings) Get added in v1.2.12

func (encodings AcceptEncodings) Get(name []byte) (quality float64, has bool)

func (AcceptEncodings) Len added in v1.2.12

func (encodings AcceptEncodings) Len() int

func (AcceptEncodings) Less added in v1.2.12

func (encodings AcceptEncodings) Less(i, j int) bool

func (AcceptEncodings) Swap added in v1.2.12

func (encodings AcceptEncodings) Swap(i, j int)

func (AcceptEncodings) WriteTo added in v1.2.21

func (encodings AcceptEncodings) WriteTo(header Header)

type Client

type Client interface {
	Do(ctx context.Context, method []byte, path []byte, header Header, body []byte) (status int, responseHeader Header, responseBody []byte, err error)
	Close()
}

type Config

type Config struct {
	Port        int             `json:"port,omitempty" yaml:"port,omitempty"`
	TLS         *TLSConfig      `json:"tls,omitempty" yaml:"tls,omitempty"`
	Options     json.RawMessage `json:"options,omitempty" yaml:"options,omitempty"`
	Middlewares json.RawMessage `json:"middlewares,omitempty" yaml:"middlewares,omitempty"`
	Handlers    json.RawMessage `json:"handlers,omitempty" yaml:"handlers,omitempty"`
}

func (*Config) GetPort

func (config *Config) GetPort() (port int, err error)

func (*Config) GetTLS

func (config *Config) GetTLS() (tls ssl.Config, err error)

func (*Config) HandlerConfig

func (config *Config) HandlerConfig(name string) (handler configures.Config, err error)

func (*Config) MiddlewareConfig

func (config *Config) MiddlewareConfig(name string) (middleware configures.Config, err error)

func (*Config) OptionsConfig

func (config *Config) OptionsConfig() (options configures.Config, err error)
type Cookie struct {
	// contains filtered or unexported fields
}

func AcquireCookie

func AcquireCookie() *Cookie

func (*Cookie) Domain

func (c *Cookie) Domain() []byte

func (*Cookie) Expire

func (c *Cookie) Expire() time.Time

func (*Cookie) HTTPOnly

func (c *Cookie) HTTPOnly() bool

func (*Cookie) Key

func (c *Cookie) Key() []byte

func (*Cookie) MaxAge

func (c *Cookie) MaxAge() int

func (*Cookie) Path

func (c *Cookie) Path() []byte

func (*Cookie) Reset

func (c *Cookie) Reset()

func (*Cookie) SameSite

func (c *Cookie) SameSite() CookieSameSite

func (*Cookie) Secure

func (c *Cookie) Secure() bool

func (*Cookie) SetDomain

func (c *Cookie) SetDomain(domain []byte)

func (*Cookie) SetExpire

func (c *Cookie) SetExpire(expire time.Time)

func (*Cookie) SetHTTPOnly

func (c *Cookie) SetHTTPOnly(httpOnly bool)

func (*Cookie) SetKey

func (c *Cookie) SetKey(key []byte)

func (*Cookie) SetMaxAge

func (c *Cookie) SetMaxAge(seconds int)

func (*Cookie) SetPath

func (c *Cookie) SetPath(path []byte)

func (*Cookie) SetSameSite

func (c *Cookie) SetSameSite(mode CookieSameSite)

func (*Cookie) SetSecure

func (c *Cookie) SetSecure(secure bool)

func (*Cookie) SetValue

func (c *Cookie) SetValue(value []byte)

func (*Cookie) Value

func (c *Cookie) Value() []byte

type CookieSameSite

type CookieSameSite int
const (
	CookieSameSiteDisabled CookieSameSite = iota
	CookieSameSiteDefaultMode
	CookieSameSiteLaxMode
	CookieSameSiteStrictMode
	CookieSameSiteNoneMode
)

type Dialer

type Dialer interface {
	Dial(address []byte) (client Client, err error)
}

type Handler

type Handler interface {
	Handle(w ResponseWriter, r Request)
}

type HandlerFunc

type HandlerFunc func(ResponseWriter, Request)

func (HandlerFunc) Handle

func (f HandlerFunc) Handle(w ResponseWriter, r Request)
type Header interface {
	Add(key []byte, value []byte)
	Set(key []byte, value []byte)
	Get(key []byte) []byte
	Del(key []byte)
	Values(key []byte) [][]byte
	Foreach(fn func(key []byte, values [][]byte))
	Len() int
	Reset()
}

func AcquireHeader

func AcquireHeader() Header

func NewHeader added in v1.2.0

func NewHeader() Header

func TryLoadRequestHeader

func TryLoadRequestHeader(ctx context.Context) (Header, bool)

func TryLoadResponseHeader

func TryLoadResponseHeader(ctx context.Context) (Header, bool)

type Marshal added in v1.2.12

type Marshal func(v any) (p []byte, err error)

func GetMarshaler added in v1.2.21

func GetMarshaler(ct []byte) (v Marshal, contentType []byte)

type Middleware

type Middleware interface {
	Name() string
	Construct(options MiddlewareOptions) error
	Handler(next Handler) Handler
	io.Closer
}

type MiddlewareOptions

type MiddlewareOptions struct {
	Log    logs.Logger
	Config configures.Config
}

type Middlewares

type Middlewares []Middleware

func WaveMiddlewares

func WaveMiddlewares(log logs.Logger, config Config, middlewares []Middleware) (v Middlewares, err error)

func (Middlewares) Close

func (middlewares Middlewares) Close()

func (Middlewares) Handler

func (middlewares Middlewares) Handler(handler Handler) Handler

type Mux

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

func NewMux

func NewMux() *Mux

func (*Mux) Add

func (mux *Mux) Add(handler MuxHandler)

func (*Mux) Handle

func (mux *Mux) Handle(w ResponseWriter, r Request)

type MuxHandler

type MuxHandler interface {
	Name() string
	Construct(options MuxHandlerOptions) error
	Match(ctx context.Context, method []byte, path []byte, header Header) bool
	Handler
}

type MuxHandlerOptions

type MuxHandlerOptions struct {
	Log    logs.Logger
	Config configures.Config
}

type Options

type Options struct {
	Log     logs.Logger
	Config  Config
	Handler Handler
}

type Params

type Params interface {
	Get(name []byte) []byte
	Set(name []byte, value []byte)
	Add(name []byte, value []byte)
	Values(name []byte) [][]byte
	Remove(name []byte)
	Len() int
	Encode() (p []byte)
}

func NewParams

func NewParams() Params

type Request

type Request interface {
	context.Context
	TLS() bool
	TLSConnectionState() *tls.ConnectionState
	RemoteAddr() []byte
	Proto() []byte
	Host() []byte
	Method() []byte
	SetMethod(method []byte)
	Header() Header
	Cookie(key []byte) (value []byte)
	SetCookie(key []byte, value []byte)
	RequestURI() []byte
	Path() []byte
	Params() Params
	FormValue(name []byte) (value []byte)
	Body() ([]byte, error)
	SetBody(body []byte)
}

func LoadRequest

func LoadRequest(ctx context.Context) Request

func TryLoadRequest

func TryLoadRequest(ctx context.Context) (Request, bool)

type ResponseWriter

type ResponseWriter interface {
	context.Context
	Status() int
	SetStatus(status int)
	SetCookie(cookie *Cookie)
	Header() Header
	Succeed(v any)
	Failed(cause error)
	Write(body []byte) (int, error)
	Body() []byte
	BodyLen() int
	ResetBody()
	Hijack(func(ctx context.Context, conn net.Conn, rw *bufio.ReadWriter) (err error)) (async bool, err error)
	Hijacked() bool
	WriteTimeout() time.Duration
	WriteDeadline() time.Time
}

func LoadResponseWriter

func LoadResponseWriter(ctx context.Context) ResponseWriter

func TryLoadResponseWriter

func TryLoadResponseWriter(ctx context.Context) (ResponseWriter, bool)

type ResultResponseWriter

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

func AcquireResultResponseWriter

func AcquireResultResponseWriter(timeout time.Duration, contentType []byte) *ResultResponseWriter

func (*ResultResponseWriter) Body

func (w *ResultResponseWriter) Body() []byte

func (*ResultResponseWriter) BodyLen

func (w *ResultResponseWriter) BodyLen() int

func (*ResultResponseWriter) Failed

func (w *ResultResponseWriter) Failed(cause error)

func (*ResultResponseWriter) Header added in v1.2.0

func (w *ResultResponseWriter) Header() (h Header)

func (*ResultResponseWriter) ResetBody added in v1.2.63

func (w *ResultResponseWriter) ResetBody()

func (*ResultResponseWriter) SetStatus

func (w *ResultResponseWriter) SetStatus(status int)

func (*ResultResponseWriter) Status

func (w *ResultResponseWriter) Status() int

func (*ResultResponseWriter) Succeed

func (w *ResultResponseWriter) Succeed(v any)

func (*ResultResponseWriter) Write

func (w *ResultResponseWriter) Write(body []byte) (int, error)

func (*ResultResponseWriter) WriteDeadline added in v1.1.1

func (w *ResultResponseWriter) WriteDeadline() time.Time

func (*ResultResponseWriter) WriteTimeout added in v1.1.1

func (w *ResultResponseWriter) WriteTimeout() time.Duration

type Server

type Server interface {
	Port() (port int)
	ListenAndServe() (err error)
	Shutdown(ctx context.Context)
}

type TLSConfig

type TLSConfig struct {
	// Kind
	// ACME
	// SSC(SELF-SIGN-CERT)
	// DEFAULT
	Kind    string          `json:"kind" yaml:"kind,omitempty"`
	Options json.RawMessage `json:"options" yaml:"options,omitempty"`
	// contains filtered or unexported fields
}

func FixedTLSConfig added in v1.1.3

func FixedTLSConfig(conf ssl.Config) *TLSConfig

func (*TLSConfig) Config

func (config *TLSConfig) Config() (conf ssl.Config, err error)

type Transport

type Transport interface {
	Name() (name string)
	Construct(options Options) (err error)
	Dialer
	Server
}

type WriteBuffer

type WriteBuffer interface {
	io.Writer
	Bytes() []byte
}

Directories

Path Synopsis
middlewares

Jump to

Keyboard shortcuts

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