webhttp

package
v0.0.0-...-b34fa9a Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2022 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDefaultInternal represents the default internal server error
	ErrDefaultInternal = &Error{
		Status: http.StatusInternalServerError,
		Code:   "internal_error",
		Desc:   "Something went wrong",
	}
)

Functions

func ParseRequestBodyJSON

func ParseRequestBodyJSON(r *http.Request, result interface{}) error

func RespondJSON

func RespondJSON(ctx context.Context, w http.ResponseWriter, obj interface{}, headers map[string]string)

Types

type CORSConfig

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

func NewCORSConfig

func NewCORSConfig(origins []string) CORSConfig

type Error

type Error struct {
	Status int    `json:"-"`
	Code   string `json:"code"`
	Desc   string `json:"description"`
}

Error represents a handler error. It contains web-related information such as HTTP status code, error code and error description

func (Error) Error

func (e Error) Error() string

Error satisfies the error interface

type HandlerFunc

type HandlerFunc func(http.ResponseWriter, *http.Request) error

type Router

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

func (*Router) Get

func (rtr *Router) Get(route string, handlerFunc HandlerFunc)

func (*Router) Group

func (rtr *Router) Group(f func(*Router))

func (*Router) Handle

func (rtr *Router) Handle(route string, h http.Handler)

func (*Router) Post

func (rtr *Router) Post(route string, handlerFunc HandlerFunc)

func (*Router) ServeHTTP

func (rtr *Router) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (Router) Use

func (rtr Router) Use(middlewares ...func(http.Handler) http.Handler)

func (*Router) With

func (rtr *Router) With(middlewares ...func(http.Handler) http.Handler) *Router

type Server

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

Server represents an HTTP server

func NewServer

func NewServer(
	watcher *watchdog.Client,
	corsCfg CORSConfig,
	readinessHF HandlerFunc,
	handler func(r *Router),
	opts ...ServerOption,
) *Server

NewServer initializes and returns an instance of Server

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

Start starts the HTTP server

type ServerOption

type ServerOption func(*Server)

ServerOption is an optional config used to modify the server's behaviour

func ServerAddr

func ServerAddr(addr string) ServerOption

ServerAddr overrides the server's default address with the given addr.

func ServerProfilingDisabled

func ServerProfilingDisabled() ServerOption

ServerProfilingDisabled disables pprof profiling.

func ServerReadTimeout

func ServerReadTimeout(duration time.Duration) ServerOption

ServerReadTimeout overrides the server's default account timeout with the given one.

func ServerShutdownGrace

func ServerShutdownGrace(duration time.Duration) ServerOption

ServerShutdownGrace overrides the server's default shutdown grace timeout with the given one.

func ServerWriteTimeout

func ServerWriteTimeout(duration time.Duration) ServerOption

ServerWriteTimeout overrides the server's default write timeout with the given one.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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