api

package
v0.0.0-...-90229f9 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2019 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HTTPErr

func HTTPErr(ctx context.Context, w http.ResponseWriter, err error)

HTTPErr is a provisional convenience helper for handling errors inside the handler Setting usermsg to a non empty string, will overwrite the the error forwarded to the user with it's value

func NewHandler

func NewHandler(ctx context.Context, f HandlerFunc) http.HandlerFunc

NewHandler returns a standard http.HandlerFunc wrapping our default encoding and error handling

Types

type Error

type Error struct {
	Err    error  `json:"-"`
	ErrStr string `json:"error,omitempty"`
}

Error implements the error interface and provides a matching implementation for Response

func (*Error) Fail

func (e *Error) Fail(err error)

Fail sets the underlying error

func (*Error) Failure

func (e *Error) Failure() error

Failure returns the underlying error

type HandlerFunc

type HandlerFunc func(context.Context, http.ResponseWriter, *http.Request) Response

HandlerFunc represents a http.HandlerFunc returning an error

type Response

type Response interface {
	// Fail should set the internal error value if existing
	Fail(error)
	// Failure should return the internal error value if existing (or nil)
	Failure() error
}

Response with basic error handling features

type Server

type Server struct {
	*http.Server

	Addr   string
	Router chi.Router
}

Server is our default wrapper for routing and serving

func New

func New(addr string, dbg bool) *Server

New Server with default router and middlewares

func (*Server) GracefulHandler

func (s *Server) GracefulHandler(ctx context.Context)

GracefulHandler watches for termination signals and takes care of graceful server shutdown

func (*Server) Shutdown

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

Shutdown the Server

func (*Server) Start

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

Start the server

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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