http

package
v1.8.3 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2025 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

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
var UnavailableResponseBodyBytes = []byte(`{
  "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 MakeClient() *fasthttp.Client

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 WriteFromRawResponse(ctx *fasthttp.RequestCtx, headers [][2][]byte, body []byte, code int, lastRefreshedAt int64)

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

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) Close

func (s *HTTP) Close() 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

type Server

type Server interface {
	ListenAndServe()
	Close() error
}

type ShardedHostPool

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

ShardedHostPool is a contention-free pool of HostClients for a single upstream.

func NewShardedHostClient

func NewShardedHostClient(addr string, https bool, shards int, tlsCfg *tls.Config, dial func(addr string) (net.Conn, error)) *ShardedHostPool

NewShardedHostClient creates a sharded pool. TLS config / Dial are optional.

func (*ShardedHostPool) DoTimeout

func (p *ShardedHostPool) DoTimeout(req *fasthttp.Request, resp *fasthttp.Response, to time.Duration) error

DoTimeout issues request using an RR shard; returns fast error if backend is DOWN (optional).

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.

func (*ShardedHttpPool) DoTimeout

func (p *ShardedHttpPool) DoTimeout(req *fasthttp.Request, resp *fasthttp.Response, to time.Duration) error

DoTimeout issues request using an RR shard; returns fast error if backend is DOWN (optional).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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