echo

package module
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: May 1, 2019 License: MIT Imports: 18 Imported by: 1

README

Echo module for Helium

Codecov Build Status Report GitHub release GitHub

Module provides boilerplate that preconfigured echo.Engine for you with custom Binder / Logger / Validator / ErrorHandler

  • bind - simple replacement for echo.Binder
  • validate - simple replacement for echo.Validate
  • logger - provides echo.Logger that pass calls to zap.Logger

Documentation

Index

Constants

This section is empty.

Variables

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

Module engine

Functions

func AddTagParsers

func AddTagParsers(parser tagParser)

AddTagParsers used in fieldName

func CheckErrors

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

CheckErrors of validator and return formatted errors:

func LoggerMiddleware added in v0.4.0

func LoggerMiddleware(log *zap.Logger) echo.MiddlewareFunc

LoggerMiddleware returns a middleware that logs HTTP requests.

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

Types

type CustomError

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

CustomError interface

type EngineParams

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

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

FieldError contains field name and validator error

func (FieldError) Error

func (f FieldError) Error() string

type FieldLevel

type FieldLevel = validator.FieldLevel

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

type Func

type Func = validator.Func

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

type ValidateParams

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

ValidateParams to call CheckErrors method

type Validator

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

Validator to implement custom echo.Validator

func NewValidator

func NewValidator() Validator

NewValidator returns custom echo.Validator

func WrapValidator

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