http

package
v0.0.0-...-8ac0413 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package http provides convenience wrappers and options for creating a http.Server instance.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ServerOption

type ServerOption func(wrapper *ServerWrapper)

ServerOption defines the function signature for helper methods to update values on the wrapper.

func WithHostPort

func WithHostPort(host, port string) ServerOption

WithHostPort sets the host and port for the server to listen on.

func WithPort

func WithPort(port string) ServerOption

WithPort sets the port for the server to listen on, and an empty host string.

func WithReadTimeout

func WithReadTimeout(timeout time.Duration) ServerOption

WithReadTimeout sets the ReadTimeout value on the underlying http.Server instance.

func WithShutdownTimeout

func WithShutdownTimeout(timeout time.Duration) ServerOption

WithShutdownTimeout sets the time to wait to try and shutdown the underlying http.Server instance gracefully.

func WithWriteTimeout

func WithWriteTimeout(timeout time.Duration) ServerOption

WithWriteTimeout sets the WriteTimeout value on the underlying http.Server instance.

type ServerWrapper

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

ServerWrapper is an abstraction to make it easier to start, shutdown and configure a http.Server instance.

func NewServerWrapper

func NewServerWrapper(logCtx zerolog.Context, rootHandler http.Handler, options ...ServerOption) *ServerWrapper

NewServerWrapper creates a new instance of a http.Server and applies the provided option functions. The error callback function is used to handle errors returned from the http.Server.ListenAndServe() function.

func (*ServerWrapper) Start

func (w *ServerWrapper) Start() error

Start uses the provided options and defaults to start the http server. It will return an error IFF the error is not http.ErrServerClosed.

func (*ServerWrapper) Stop

func (w *ServerWrapper) Stop()

Stop attempts to gracefully stop the server, and if it passes the timeout will force close.

Jump to

Keyboard shortcuts

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