server

package
v0.0.0-...-6ebe9bd Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrCase

func ErrCase(code int, errors ...error) map[int][]error

func ErrorHandler

func ErrorHandler(logger *log.Logger) echo.HTTPErrorHandler

func NewHTTPError

func NewHTTPError(err error, errorCases ...map[int][]error) error

Types

type CORSConfig

type CORSConfig struct {
	AllowCredentials bool `default:"true"`
	Headers          []string
	Methods          []string
	Origins          []string
}

CORSConfig configures CORS.

type Config

type Config struct {
	Debug        bool          `default:"true"`
	Address      string        `default:":8080"`
	ReadTimeout  time.Duration `default:"1m"`
	WriteTimeout time.Duration `default:"1m"`
	CORS         CORSConfig
}

Config configures the server.

type HTTPError

type HTTPError struct {
	Message   string      `json:"message"`
	Details   interface{} `json:"details,omitempty"`
	Code      int         `json:"code,omitempty"` // Unique application error code.
	HTTPCode  int         `json:"-"`              // HTTP status code.
	Err       error       `json:"-"`
	RequestID string      `json:"request_id,omitempty"`
}

Error represents a handler error.

func GenericInternalServerError

func GenericInternalServerError() *HTTPError

func (*HTTPError) Error

func (e *HTTPError) Error() string

Error returns the error message.

type REST

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

REST represents a REST server.

func New

func New(cfg Config, clock service.Clock, logger *log.Logger) *REST

New creates a new REST web server.

func (*REST) Routes

func (r *REST) Routes() *echo.Group

func (*REST) Run

func (r *REST) Run() error

Run runs the REST server.

func (*REST) SetErrorHandler

func (r *REST) SetErrorHandler(errorHandler echo.HTTPErrorHandler)

SetErrorHandler sets the error handler.

func (*REST) SetValidation

func (r *REST) SetValidation(validator echo.Validator, binder echo.Binder)

SetValidation sets the validator and binder that validate incoming payload.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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