transports

package
v1.0.32 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2023 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MethodGET  = []byte(http.MethodGet)
	MethodPost = []byte(http.MethodPost)
)
View Source
var (
	ErrTooBigRequestBody = errors.Warning("fns: request body is too big")
)

Functions

func ConvertRequestToHttpRequest added in v1.0.14

func ConvertRequestToHttpRequest(req *Request) (r *http.Request, err error)

func ConvertResponseWriterToHttpResponseWriter added in v1.0.14

func ConvertResponseWriterToHttpResponseWriter(writer ResponseWriter) (w http.ResponseWriter)

func FastHttpTransportHandlerAdaptor

func FastHttpTransportHandlerAdaptor(h Handler) fasthttp.RequestHandler

func HttpTransportHandlerAdaptor

func HttpTransportHandlerAdaptor(h Handler, maxRequestBody int) http.Handler

func Register

func Register(transport Transport)

Types

type Client

type Client interface {
	Do(ctx context.Context, request *Request) (response *Response, err error)
	Close()
}

type CorsConfig

type CorsConfig struct {
	AllowedOrigins      []string `json:"allowedOrigins"`
	AllowedHeaders      []string `json:"allowedHeaders"`
	ExposedHeaders      []string `json:"exposedHeaders"`
	AllowCredentials    bool     `json:"allowCredentials"`
	MaxAge              int      `json:"maxAge"`
	AllowPrivateNetwork bool     `json:"allowPrivateNetwork"`
}

func (*CorsConfig) Handler

func (config *CorsConfig) Handler(handler Handler) Handler

func (*CorsConfig) TryFillAllowedHeaders

func (config *CorsConfig) TryFillAllowedHeaders(headers []string)

func (*CorsConfig) TryFillExposedHeaders

func (config *CorsConfig) TryFillExposedHeaders(headers []string)

type Dialer

type Dialer interface {
	Dial(address string) (client Client, err error)
}

type FastHttpClientOptions added in v1.0.12

type FastHttpClientOptions struct {
	DialDualStack             bool   `json:"dialDualStack"`
	MaxConnsPerHost           int    `json:"maxConnsPerHost"`
	MaxIdleConnDuration       string `json:"maxIdleConnDuration"`
	MaxConnDuration           string `json:"maxConnDuration"`
	MaxIdemponentCallAttempts int    `json:"maxIdemponentCallAttempts"`
	ReadBufferSize            string `json:"readBufferSize"`
	ReadTimeout               string `json:"readTimeout"`
	WriteBufferSize           string `json:"writeBufferSize"`
	WriteTimeout              string `json:"writeTimeout"`
	MaxResponseBodySize       string `json:"maxResponseBodySize"`
	MaxConnWaitTimeout        string `json:"maxConnWaitTimeout"`
}

type FastHttpTransportOptions added in v1.0.12

type FastHttpTransportOptions struct {
	ReadBufferSize        string                `json:"readBufferSize"`
	ReadTimeout           string                `json:"readTimeout"`
	WriteBufferSize       string                `json:"writeBufferSize"`
	WriteTimeout          string                `json:"writeTimeout"`
	MaxIdleWorkerDuration string                `json:"maxIdleWorkerDuration"`
	TCPKeepalive          bool                  `json:"tcpKeepalive"`
	TCPKeepalivePeriod    string                `json:"tcpKeepalivePeriod"`
	MaxRequestBodySize    string                `json:"maxRequestBodySize"`
	ReduceMemoryUsage     bool                  `json:"reduceMemoryUsage"`
	MaxRequestsPerConn    int                   `json:"maxRequestsPerConn"`
	KeepHijackedConns     bool                  `json:"keepHijackedConns"`
	StreamRequestBody     bool                  `json:"streamRequestBody"`
	Prefork               bool                  `json:"prefork"`
	Client                FastHttpClientOptions `json:"client"`
}

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 http.Header

func (Header) Add

func (h Header) Add(key, value string)

func (Header) Authorization

func (h Header) Authorization() string

func (Header) ClearSiteData added in v1.0.22

func (h Header) ClearSiteData(scopes ...string)

func (Header) Clone

func (h Header) Clone() Header

func (Header) Connection

func (h Header) Connection() string

func (Header) Del

func (h Header) Del(key string)

func (Header) Get

func (h Header) Get(key string) string

func (Header) IsConnectionClosed

func (h Header) IsConnectionClosed() bool

func (Header) Set

func (h Header) Set(key, value string)

func (Header) SetConnectionClose

func (h Header) SetConnectionClose()

func (Header) Upgrade

func (h Header) Upgrade() string

func (Header) Values

func (h Header) Values(key string) []string

type Options

type Options struct {
	Port      int
	ServerTLS *tls.Config
	ClientTLS *tls.Config
	Handler   Handler
	Log       logs.Logger
	Config    configures.Config
}

type Request

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

func NewRequest

func NewRequest(ctx context.Context, method []byte, uri []byte) (r *Request, err error)

func NewUnsafeRequest

func NewUnsafeRequest(ctx context.Context, method []byte, uri []byte) (r *Request)

func (*Request) Body

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

func (*Request) Context

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

func (*Request) Header

func (r *Request) Header() Header

func (*Request) Host

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

func (*Request) IsGet

func (r *Request) IsGet() bool

func (*Request) IsPost

func (r *Request) IsPost() bool

func (*Request) IsTLS

func (r *Request) IsTLS() bool

func (*Request) Method

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

func (*Request) Param

func (r *Request) Param(name string) []byte

func (*Request) Params

func (r *Request) Params() RequestParams

func (*Request) Path

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

func (*Request) Proto added in v1.0.14

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

func (*Request) RemoteAddr

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

func (*Request) SetBody

func (r *Request) SetBody(body []byte)

func (*Request) SetHost

func (r *Request) SetHost(host []byte)

func (*Request) SetProto added in v1.0.14

func (r *Request) SetProto(proto []byte)

func (*Request) TLSConnectionState added in v1.0.14

func (r *Request) TLSConnectionState() *tls.ConnectionState

func (*Request) URL

func (r *Request) URL() ([]byte, error)

func (*Request) UseTLS

func (r *Request) UseTLS()

func (*Request) WithContext

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

type RequestParams

type RequestParams map[string][]byte

func (RequestParams) Add

func (params RequestParams) Add(name []byte, value []byte)

func (RequestParams) Del

func (params RequestParams) Del(name []byte)

func (RequestParams) Get

func (params RequestParams) Get(name []byte) []byte

func (RequestParams) Len

func (params RequestParams) Len() int

func (RequestParams) String

func (params RequestParams) String() string

type Response

type Response struct {
	Status int
	Header Header
	Body   []byte
}

type ResponseWriter

type ResponseWriter interface {
	Status() int
	SetStatus(status int)
	Header() Header
	Succeed(v interface{})
	Failed(cause errors.CodeError)
	Write(body []byte) (int, error)
	Body() []byte
	Hijack(func(conn net.Conn, rw *bufio.ReadWriter) (err error)) (async bool, err error)
	Hijacked() bool
}

type Transport

type Transport interface {
	Name() (name string)
	Build(options Options) (err error)
	Dialer
	ListenAndServe() (err error)
	io.Closer
}

func Registered

func Registered(name string) (transport Transport, has bool)

type WriteBuffer

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

Jump to

Keyboard shortcuts

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