server

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2020 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CtxRequestID contextKey = iota
)

Context value parameters

View Source
const (
	HeaderRequestID = "X-Request-ID"
)

Header constants

Variables

View Source
var (
	ErrMissingBody        = errors.New("missing body")
	ErrInvalidRequest     = errors.New("invalid request")
	ErrInvalidRequestBody = errors.New("invalid request body")
	ErrBodyTooLarge       = errors.New("body too large")
)

Errors

Functions

This section is empty.

Types

type Option

type Option func(*TySugServer)

Option is a handy type used for configuration purposes

func WithCORS added in v0.0.2

func WithCORS(allowedOrigins []string) Option

WithCORS adds the CORS handler to the request handling

func WithDefaultHeaders added in v0.1.0

func WithDefaultHeaders(headers http.Header) Option

WithDefaultHeaders sets the default headers to be used when writing a response.

func WithGzipHandler added in v0.0.2

func WithGzipHandler() Option

WithGzipHandler adds a gzip handler to the server's handlers

func WithInputLimitValidator added in v0.0.2

func WithInputLimitValidator(inputMax int) Option

WithInputLimitValidator specifies a max input-value limit validator

func WithLogger

func WithLogger(logger *logrus.Logger) Option

WithLogger sets the logger to be used when encountering http-related errors. Errors are written to the standard error output in most cases. Printing on the standard output is reserved to extreme case where writing on stderr failed.

func WithPProf added in v0.0.3

func WithPProf(prefix string) Option

WithPProf enables pprof

type Service

type Service interface {
	Find(ctx context.Context, input string) (string, float64, bool)
}

Service is the type any service must implement

type ServiceRegistry added in v0.0.2

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

ServiceRegistry holds (opinionated) service objects for handling specific requests

func NewServiceRegistry added in v0.0.2

func NewServiceRegistry() ServiceRegistry

NewServiceRegistry creates a new registry

func (ServiceRegistry) GetServiceForList added in v0.0.2

func (rlh ServiceRegistry) GetServiceForList(name string) Service

GetServiceForList returns a service able to handle a specific list

func (ServiceRegistry) HasServiceForList added in v0.0.2

func (rlh ServiceRegistry) HasServiceForList(name string) bool

HasServiceForList returns true only if a service has been registered for a certain list

func (*ServiceRegistry) Register added in v0.0.2

func (rlh *ServiceRegistry) Register(listName string, svc Service) *ServiceRegistry

Register registers a new service with a list of references

type TySugServer

type TySugServer struct {
	Logger *logrus.Logger
	// contains filtered or unexported fields
}

TySugServer the HTTP server

func NewHTTP

func NewHTTP(sr ServiceRegistry, mux *http.ServeMux, options ...Option) TySugServer

NewHTTP constructs a new TySugServer

func (*TySugServer) ListenOnAndServe

func (tss *TySugServer) ListenOnAndServe(addr string) error

ListenOnAndServe allows to set the host:port URL late. It calls ListenAndServe()

type Validator added in v0.0.2

type Validator func(TSRequest tySugRequest) error

Validator is a type to validate a client request, returning a nil error means all went well.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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