Documentation

Index

Constants

View Source
const (
	HeaderTotalCount = "X-Total-Count"
)

Variables

This section is empty.

Functions

func Bind

func Bind(c echo.Context, doc interface{}) error

Use this binding instead of Echo.Binding()

func GetJWTClaims

func GetJWTClaims(c echo.Context) jwt.MapClaims

Decode token

func GetJWTFromHeader

func GetJWTFromHeader(c echo.Context) (string, error)

Extracts token from the request header.

func GetJWTSignedString

func GetJWTSignedString(data jwt.MapClaims) (string, error)

JWT signed string

func GetRefreshJWTSignedString

func GetRefreshJWTSignedString(data jwt.MapClaims) (string, error)

JWT signed string with long expire

func InitCacheMiddleware

func InitCacheMiddleware(capacity int, ttl time.Duration) error

func InitJWTMiddleware

func InitJWTMiddleware(config JWTConfig) error

Must be call before use JWT

func InitKeyAuthMiddleware

func InitKeyAuthMiddleware(key string) error

func JWTWithAuthHandler

func JWTWithAuthHandler(handler MiddlewareHandler) echo.MiddlewareFunc

func JWTWithDefault

func JWTWithDefault(skipper middleware.Skipper) echo.MiddlewareFunc

func KeyAuthMiddleware

func KeyAuthMiddleware() echo.MiddlewareFunc

func ParseToken

func ParseToken(tokenString string) (*jwt.Token, error)

Types

type Error

type Error struct {

	// contains filtered or unexported fields

}

func NewError

func NewError(code int, message string) *Error

func (*Error) Code

func (e *Error) Code() int

func (*Error) Error

func (e *Error) Error() string

type HandlerBase

type HandlerBase struct {
	// contains filtered or unexported fields

}

func (*HandlerBase) Aggregate

func (h *HandlerBase) Aggregate(c echo.Context,
	pipeline, docs interface{}) error

func (*HandlerBase) AggregateOne

func (h *HandlerBase) AggregateOne(c echo.Context,
	pipeline interface{}, doc interface{}) error

func (*HandlerBase) DeleteOne

func (h *HandlerBase) DeleteOne(c echo.Context, doc interface{}) error

func (*HandlerBase) Find

func (h *HandlerBase) Find(c echo.Context, projection, docs interface{}) error

func (*HandlerBase) FindOne

func (h *HandlerBase) FindOne(c echo.Context, projection interface{}, doc interface{}) error

func (*HandlerBase) Head

func (h *HandlerBase) Head(c echo.Context, f interface{}) error

/ Find one document without body

func (*HandlerBase) Init

func (h *HandlerBase) Init(db db.DatabaseBase, collection string, repo RepositoryInterface)

func (*HandlerBase) Insert

func (h *HandlerBase) Insert(c echo.Context, doc interface{}) error

func (*HandlerBase) UpdateOne

func (h *HandlerBase) UpdateOne(c echo.Context, doc interface{}) error

type JWTConfig

type JWTConfig struct {
	// Algorithm: HS256, HS384, HS512, RS256, RS384, RS512, ES256, ES384, ES512, None
	SigningMethod string `yaml:"signingMethod"`
	// Secrect key
	SigningKey string `yaml:"signingKey"`
	// How many ms that token will be expired
	Expire time.Duration `yaml:"expire"`
	// How many ms that refresh token will be expired
	RefreshExpire time.Duration `yaml:"refreshExpire"`
}

func GetJWTConfig

func GetJWTConfig() JWTConfig

func (*JWTConfig) IsValid

func (c *JWTConfig) IsValid() bool

type LifeCycle

type LifeCycle struct {
	BeforeFind      func(params filter.Params, filter *interface{}, option *db.FindOption, projection interface{}) error
	AfterFind       func(params filter.Params, docs interface{}) error
	BeforeFindOne   func(params filter.Params, filter, projection interface{}) error
	AfterFindOne    func(params filter.Params, doc interface{}) error
	BeforeInsert    func(params filter.Params, doc interface{}) error
	AfterInsert     func(params filter.Params, doc interface{}) error
	BeforeUpdateOne func(params filter.Params, filter, doc interface{}) error
	AfterUpdateOne  func(params filter.Params, doc interface{}) error
	BeforeDeleteOne func(params filter.Params, filter interface{}) error
	AfterDeleteOne  func(params filter.Params, doc interface{}) error
}

type MiddlewareHandler

type MiddlewareHandler func(next echo.HandlerFunc, c echo.Context) error

type RepositoryBase

type RepositoryBase struct {
	Driver db.DatabaseBase

	// contains filtered or unexported fields

}

func (*RepositoryBase) Aggregate

func (r *RepositoryBase) Aggregate(params filter.Params, ctx context.Context, pipeline, docs interface{}) (int64, error)

func (*RepositoryBase) AggregateOne

func (r *RepositoryBase) AggregateOne(params filter.Params, ctx context.Context, pipeline interface{}, doc interface{}) error

func (*RepositoryBase) DeleteOne

func (r *RepositoryBase) DeleteOne(params filter.Params, ctx context.Context, filter interface{}) (interface{}, error)

func (*RepositoryBase) EnsureIndexs

func (r *RepositoryBase) EnsureIndexs()

func (*RepositoryBase) Find

func (r *RepositoryBase) Find(params filter.Params, ctx context.Context, filter interface{}, option db.FindOption,
	projection, docs interface{}) (int64, error)

func (*RepositoryBase) FindOne

func (r *RepositoryBase) FindOne(params filter.Params, ctx context.Context, filter, projection interface{}, doc interface{}) error

func (*RepositoryBase) Head

func (r *RepositoryBase) Head(params filter.Params, ctx context.Context, filter interface{}) int64

/ Find one document without body

func (*RepositoryBase) Init

func (r *RepositoryBase) Init(db db.DatabaseBase, collection string)

func (*RepositoryBase) Insert

func (r *RepositoryBase) Insert(params filter.Params, ctx context.Context, doc interface{}, validateFunc func(interface{}) error) (interface{}, error)

func (*RepositoryBase) RegisterLifeCycle

func (r *RepositoryBase) RegisterLifeCycle(l LifeCycle)

func (*RepositoryBase) UpdateOne

func (r *RepositoryBase) UpdateOne(params filter.Params, ctx context.Context, filter, doc interface{}, validateFunc func(interface{}) error) (interface{}, error)

type RepositoryInterface

type RepositoryInterface interface {
	EnsureIndexs()
	Init(db db.DatabaseBase, collection string)
	RegisterLifeCycle(l LifeCycle)
	Find(params filter.Params, ctx context.Context, filter interface{}, option db.FindOption,
		projection, docs interface{}) (int64, error)
	FindOne(params filter.Params, ctx context.Context, filter, projection interface{}, doc interface{}) error
	Aggregate(params filter.Params, ctx context.Context, pipeline, docs interface{}) (int64, error)
	AggregateOne(params filter.Params, ctx context.Context, pipeline interface{}, doc interface{}) error
	Head(params filter.Params, ctx context.Context, filter interface{}) int64
	Insert(params filter.Params, ctx context.Context, doc interface{}, validateFunc func(interface{}) error) (interface{}, error)
	UpdateOne(params filter.Params, ctx context.Context, filter, doc interface{}, validateFunc func(interface{}) error) (interface{}, error)
	DeleteOne(params filter.Params, ctx context.Context, filter interface{}) (interface{}, error)
}

type RouterBase

type RouterBase interface {
	Init(e *echo.Echo, db db.DatabaseBase)
	GetRepository() RepositoryInterface
}

type ServerConfig

type ServerConfig struct {
	Host          string        `yaml:"host"`
	Port          int           `yaml:"port"`
	BodyLimit     string        `yaml:"bodyLimit"`
	Gzip          bool          `yaml:"gzip"`
	GzipLevel     int           `yaml:"gzipLevel"`
	CacheCapacity int           `yaml:"cacheCapacity"`
	CacheTTL      time.Duration `yaml:"cacheTTL"`
}

Directories

Path Synopsis
filter