server

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2018 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrHandlerConfigIsNotFull will be returned if some handlers Config fields are not populated
	ErrHandlerConfigIsNotFull = errors.New("some handler Config fields are not populated")
	// ErrServerConfigIsNotFull will be returned if some servers Config fields are not populated
	ErrServerConfigIsNotFull = errors.New("some server Config fields are not populated")
	// ErrRouterConfigIsNotFull will be returned if some servers Config fields are not populated
	ErrRouterConfigIsNotFull = errors.New("some router Config fields are not populated")
)

Functions

func GetLimitAndOffsetParams

func GetLimitAndOffsetParams(values url.Values) (offset uint64, limit uint64, err error)

GetLimitAndOffsetParams parses offset anf limit from url values

func NewBaseRouter

func NewBaseRouter(h BaseHTTPHandler, cfg BaseRouterCfg) (*mux.Router, error)

NewBaseRouter will return new router with already registered standard endpoints /version.json - to serve service version {cfg.ApiDefinition} - to serve api schema {ProfilerPath} - to serve http profiler

func NewBaseServer added in v1.0.5

func NewBaseServer(router http.Handler, tlsCerts []tls.Certificate, listenAddr string) *http.Server

NewBaseServer will cinstruct http server with base configurations. Timeouts|TLS|CORS

Types

type BaseHTTPHandler

type BaseHTTPHandler struct {
	Logger logrus.FieldLogger
}

BaseHTTPHandler stores common dependencies and methods for any http api in system.

func (BaseHTTPHandler) GetLimitAndOffset added in v1.0.3

func (BaseHTTPHandler) GetLimitAndOffset(values url.Values) (offset uint64, limit uint64, err error)

GetLimitAndOffset will return parsed limit and offset from url.Values.

func (BaseHTTPHandler) NewLoggingResponseWriter

func (h BaseHTTPHandler) NewLoggingResponseWriter(w http.ResponseWriter, r *http.Request) LoggingResponseWriter

NewLoggingResponseWriter creates new loggingResponseWriter instance for particular request

type BaseRouterCfg added in v1.0.3

type BaseRouterCfg struct {
	ServiceVersion string

	ProfilerPath string

	APIDefinition     io.Reader
	APIDefinitionPath string
}

BaseRouterCfg stores configs for base router

type LoggingResponseWriter

type LoggingResponseWriter interface {
	http.ResponseWriter
	// Log will log request result
	Log()
	// WriteHeaderWithErr same as WriteHeader but also will set and Log error with metadata
	WriteHeaderWithErr(code int, err error)
	// WriteJSON is a helper that will set corresponding content type, encode your data and Log response
	WriteJSON(data interface{}, status ...int)
	// WriteXML is a helper that will set corresponding content type, encode your data and Log response
	WriteXML(data interface{}, status ...int)
}

LoggingResponseWriter describes methods of loggingResponseWriter helper

Jump to

Keyboard shortcuts

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