web

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2019 License: MIT Imports: 19 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EngineModule = module.Module{
	{Constructor: NewValidator},
	{Constructor: NewBinder},
	{Constructor: NewEngine},
}

Null is /dev/null emulation

View Source
var (
	// ServersModule of web base structs
	ServersModule = module.Module{
		{Constructor: NewAPIServer},
		{Constructor: NewMetricsServer},
		{Constructor: NewPprofServer},
		{Constructor: NewMultiServer},
	}
)

Functions

func AddTagParsers added in v0.5.0

func AddTagParsers(parser tagParser)

AddTagParsers used in fieldName

func CheckErrors added in v0.5.0

func CheckErrors(opts ValidateParams) (ok bool, err error)

CheckErrors of validator and return formatted errors:

func NewBinder

func NewBinder(v Validator) echo.Binder

NewBinder returns custom echo.Binder

func NewEngine

func NewEngine(params EngineParams) *echo.Echo

NewEngine returns configured echo engine

func NewLogger

func NewLogger(log *zap.Logger) echo.Logger

NewLogger converts zap.Logger to echo.Logger

func NewMultiServer added in v0.5.0

func NewMultiServer(params MultiServerParams) mserv.Server

NewMultiServer returns new multi servers group

Types

type APIParams added in v0.5.0

type APIParams struct {
	dig.In

	Config  *viper.Viper
	Logger  logger.StdLogger
	Handler http.Handler `optional:"true"`
}

APIParams struct

type CustomError added in v0.4.1

type CustomError interface {
	FormatResponse(ctx echo.Context) error
}

CustomError interface

type EmptyWriter

type EmptyWriter struct{}

EmptyWriter struct

func (EmptyWriter) Write

func (EmptyWriter) Write(data []byte) (int, error)

Write /dev/null emulation

type EngineParams added in v0.5.0

type EngineParams struct {
	dig.In

	Config     *viper.Viper   `optional:"true"`
	Binder     echo.Binder    `optional:"true"`
	Logger     *zap.Logger    `optional:"true"`
	EchoLogger echo.Logger    `optional:"true"`
	Validator  echo.Validator `optional:"true"`
}

EngineParams struct

type FieldError added in v0.5.0

type FieldError struct {
	Field     string
	Message   string
	Validator validator.FieldError
}

FieldError contains field name and validator error

func (FieldError) Error added in v0.5.0

func (f FieldError) Error() string

type FieldLevel added in v0.5.0

type FieldLevel = validator.FieldLevel

FieldLevel contains all the information and helper functions to validate a field

type Func added in v0.5.0

type Func = validator.Func

Func accepts a FieldLevel interface for all validation needs. The return value should be true when validation succeeds.

type MultiServerParams added in v0.5.0

type MultiServerParams struct {
	dig.In

	Logger  logger.StdLogger
	Servers []mserv.Server `group:"web_server"`
}

MultiServerParams struct

type ServerResult added in v0.5.0

type ServerResult struct {
	dig.Out

	Server mserv.Server `group:"web_server"`
}

ServerResult struct

func NewAPIServer added in v0.5.0

func NewAPIServer(v *viper.Viper, l logger.StdLogger, h http.Handler) ServerResult

NewAPIServer creates api server by http.Handler from DI container

func NewMetricsServer added in v0.5.0

func NewMetricsServer(v *viper.Viper, l logger.StdLogger) ServerResult

NewMetricsServer returns wrapped prometheus http server

func NewPprofServer added in v0.5.0

func NewPprofServer(v *viper.Viper, l logger.StdLogger) ServerResult

NewPprofServer returns wrapped pprof http server

type ValidateParams added in v0.5.0

type ValidateParams struct {
	Struct    interface{}
	Errors    error
	Formatter func(fields []*FieldError) string
}

ValidateParams to call CheckErrors method

type Validator added in v0.5.0

type Validator interface {
	Validate(i interface{}) error
	Register(tag string, fn Func) error
}

Validator to implement custom echo.Validator

func NewValidator added in v0.5.0

func NewValidator() Validator

NewValidator returns custom echo.Validator

func WrapValidator added in v0.5.0

func WrapValidator(v *validator.Validate) Validator

WrapValidator wraps v9.validator

Jump to

Keyboard shortcuts

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