transports

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2023 License: Apache-2.0 Imports: 26 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ContentTypeHeaderName                        = []byte("Content-Type")
	ContentTypeJsonHeaderValue                   = []byte("application/json")
	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")
	ResponseRetryAfterHeaderName                 = []byte("Retry-After")
	ResponseTimingAllowOriginHeaderName          = []byte("Timing-Allow-Origin")
	ResponseXFrameOptionsSameOriginHeaderName    = []byte("SAMEORIGIN")
	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 DecodeParams

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

func DeviceIp

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

func ParamsScanner

func ParamsScanner(params Params) scanner.Scanner

func ReleaseCookie

func ReleaseCookie(c *Cookie)

func ReleaseHeader

func ReleaseHeader(h Header)

func ReleaseResultResponseWriter

func ReleaseResultResponseWriter(w *ResultResponseWriter)

func WithRequest

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

func WithResponse

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

Types

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 TryLoadRequestHeader

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

func TryLoadResponseHeader

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

type Middleware

type Middleware interface {
	Name() string
	Construct(options MiddlewareOptions) error
	Handler(next Handler) Handler
	Close()
}

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
	Middlewares []Middleware
	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)
	Path() []byte
	Params() Params
	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 interface{})
	Failed(cause error)
	Write(body []byte) (int, error)
	Body() []byte
	BodyLen() int
	Hijack(func(conn net.Conn, rw *bufio.ReadWriter) (err error)) (async bool, err error)
	Hijacked() bool
}

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() *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) SetStatus

func (w *ResultResponseWriter) SetStatus(status int)

func (*ResultResponseWriter) Status

func (w *ResultResponseWriter) Status() int

func (*ResultResponseWriter) Succeed

func (w *ResultResponseWriter) Succeed(v interface{})

func (*ResultResponseWriter) Write

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

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"`
}

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