server

package
v0.0.0-...-c62bbba Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultIdleTimeout is the default idle timeout used for http server.
	DefaultIdleTimeout = 30 * time.Second
	// DefaultReadTimeout is the default read timeout used for http server.
	DefaultReadTimeout = 30 * time.Second
	// DefaultWriteTimeout is the default write timeout used for http server.
	DefaultWriteTimeout = 30 * time.Second
	// DefaultMaxHeaderBytes is the default max header used for http server.
	DefaultMaxHeaderBytes = 8190
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Configuration

type Configuration struct {
	Port           int
	IdleTimeout    time.Duration
	ReadTimeout    time.Duration
	WriteTimeout   time.Duration
	MaxHeaderBytes int
}

Configuration contains the necessary configuration to setup http server.

type Option

type Option func(*Server)

Option is a functional option for Server.

func WithDecompress

func WithDecompress() Option

WithDecompress decompresses request body based if content encoding type is set to "gzip" with default config.

func WithGzip

func WithGzip() Option

WithGzip compresses HTTP response using gzip compression scheme.

func WithRecover

func WithRecover(logger *slog.Logger) Option

WithRecover recovers from panic.

type Route

type Route struct {
	Method      string
	Path        string
	Handler     echo.HandlerFunc
	Middlewares []echo.MiddlewareFunc
}

Route contains the information for matching against requests.

func LivenessRoute

func LivenessRoute() Route

LivenessRoute checks if the service is alive.

func ReadinessRoute

func ReadinessRoute() Route

ReadinessRoute checks if the service and its dependencies are healthy.

type Server

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

Server serves http server.

func New

func New(port int, opts ...Option) Server

New creates a new server with default configuration.

func NewWithConfig

func NewWithConfig(c Configuration, opts ...Option) Server

NewWithConfig creates a new server with given configuration.

func (Server) AddRoute

func (s Server) AddRoute(route Route)

AddRoute registers a new route for an http method and path with matching handler in the router with optional route-level middleware.

func (Server) Shutdown

func (s Server) Shutdown(ctx context.Context) error

Shutdown stops the server gracefully.

func (Server) Start

func (s Server) Start() error

Start starts an HTTP server.

Jump to

Keyboard shortcuts

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