Documentation
¶
Index ¶
- Variables
- func DisableCompression()
- func EnableCompression()
- func IsCompressionEnabled() bool
- func MakeClient() *fasthttp.Client
- func MakeHostClient(addr string) *fasthttp.HostClient
- func SetLastUpdatedAtValueFastHttp(r *fasthttp.RequestCtx, v int64)
- func WriteFromEntry(ctx *fasthttp.RequestCtx, entry *model.Entry) error
- func WriteFromRawResponse(ctx *fasthttp.RequestCtx, headers [][2][]byte, body []byte, code int, ...)
- func WriteFromResponse(ctx *fasthttp.RequestCtx, resp *fasthttp.Response, lastRefreshedAt int64)
- type CompressionMiddleware
- type Controller
- type HTTP
- type Middleware
- type PanicRecoverMiddleware
- type Server
- type ShardedHostPool
- type ShardedHttpPool
Constants ¶
This section is empty.
Variables ¶
View Source
var Http = MakeClient()
Http is the work-horse RoundTripper (only: IPV4).
View Source
var InternalServerErrorResponseBodyBytes = []byte(`{
"status": 500,
"error": "Internal Server Error",
"message": "Something went wrong. Please contact support immediately."
}`)
View Source
var NetDialer = func(addr string) (net.Conn, error) { d := &net.Dialer{ Timeout: 3 * time.Second, KeepAlive: 30 * time.Second, } c, err := d.Dial("tcp", addr) if err != nil { return nil, err } if tc, ok := c.(*net.TCPConn); ok { _ = tc.SetNoDelay(true) _ = tc.SetKeepAlive(true) _ = tc.SetKeepAlivePeriod(30 * time.Second) _ = tc.SetLinger(-1) _ = tc.SetReadBuffer(rwBufferSize) _ = tc.SetWriteBuffer(rwBufferSize) } return c, nil }
View Source
var (
PanicsCounter = atomic.Uint64{}
)
View Source
var TLSConfig = &tls.Config{ MinVersion: tls.VersionTLS12, ClientSessionCache: tls.NewLRUClientSessionCache(connsPerHost * 1.5), }
View Source
"status": 503,
"error": "Service Unavailable",
"message": "Sorry for that, please try again later or contact support."
}`)
Functions ¶
func DisableCompression ¶
func DisableCompression()
func EnableCompression ¶
func EnableCompression()
func IsCompressionEnabled ¶
func IsCompressionEnabled() bool
func MakeClient ¶
func MakeHostClient ¶
func MakeHostClient(addr string) *fasthttp.HostClient
func SetLastUpdatedAtValueFastHttp ¶
func SetLastUpdatedAtValueFastHttp(r *fasthttp.RequestCtx, v int64)
func WriteFromEntry ¶
func WriteFromEntry(ctx *fasthttp.RequestCtx, entry *model.Entry) error
func WriteFromRawResponse ¶
func WriteFromResponse ¶
func WriteFromResponse(ctx *fasthttp.RequestCtx, resp *fasthttp.Response, lastRefreshedAt int64)
Types ¶
type CompressionMiddleware ¶
type CompressionMiddleware struct {
// contains filtered or unexported fields
}
func NewCompressionMiddleware ¶
func NewCompressionMiddleware(cfg *config.Compression) CompressionMiddleware
func (CompressionMiddleware) Middleware ¶
func (m CompressionMiddleware) Middleware(next fasthttp.RequestHandler) fasthttp.RequestHandler
Middleware builds the compressed handler once and switches per request via the atomic flag. No per-request allocations; Accept-Encoding parsing and encoder pooling are done by fasthttp.
type Controller ¶
type Controller interface {
// AddRoute is a method which must take a *fasthttp.router.Router and add new route.
// Must be implemented into each RestApi and so on controllers for inject them
// into the server for serving them.
//
// Commonly may be represented as:
// router.
// Path(CreatePath).
// HandlerFunc(c.Create).
// Methods(http.MethodPost)
AddRoute(router *router.Router)
}
type HTTP ¶
type HTTP struct {
// contains filtered or unexported fields
}
func New ¶
func New( ctx context.Context, config config.Config, controllers []Controller, middlewares []Middleware, ) (*HTTP, error)
func (*HTTP) ListenAndServe ¶
func (s *HTTP) ListenAndServe()
type Middleware ¶
type Middleware interface {
Middleware(handler fasthttp.RequestHandler) fasthttp.RequestHandler
}
type PanicRecoverMiddleware ¶
type PanicRecoverMiddleware struct {
}
func NewPanicRecoverMiddleware ¶
func NewPanicRecoverMiddleware() PanicRecoverMiddleware
func (PanicRecoverMiddleware) Middleware ¶
func (m PanicRecoverMiddleware) Middleware(next fasthttp.RequestHandler) fasthttp.RequestHandler
type ShardedHostPool ¶
type ShardedHostPool struct {
// contains filtered or unexported fields
}
ShardedHostPool is a contention-free pool of HostClients for a single upstream.
type ShardedHttpPool ¶
type ShardedHttpPool struct {
// contains filtered or unexported fields
}
ShardedHttpPool is a contention-free pool of HostClients for a single upstream.
func NewShardedHttpClient ¶
func NewShardedHttpClient(addr string, shards int, dial func(addr string) (net.Conn, error)) *ShardedHttpPool
NewShardedHttpClient creates a sharded pool. TLS config / Dial are optional.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.