rest

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2020 License: MIT Imports: 14 Imported by: 0

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 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, filter interface{}) error

func (*HandlerBase) Find

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

func (*HandlerBase) FindOne

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

func (*HandlerBase) Head

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

/ Find one document without body

func (*HandlerBase) Init

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

func (*HandlerBase) Insert

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

func (*HandlerBase) RegisterLifeCycle

func (h *HandlerBase) RegisterLifeCycle(l LifeCycle)

func (*HandlerBase) UpdateOne

func (h *HandlerBase) UpdateOne(c echo.Context,
	filter, 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(c echo.Context, filter *interface{}, option *db.FindOption, projection interface{}) error
	AfterFind       func(c echo.Context, docs interface{}) error
	BeforeFindOne   func(c echo.Context, filter, projection interface{}) error
	AfterFindOne    func(c echo.Context, doc interface{}) error
	BeforeInsert    func(c echo.Context, doc interface{}) error
	AfterInsert     func(c echo.Context, doc interface{}) error
	BeforeUpdateOne func(c echo.Context, filter, doc interface{}) error
	AfterUpdateOne  func(c echo.Context, doc interface{}) error
	BeforeDeleteOne func(c echo.Context, filter interface{}) error
	AfterDeleteOne  func(c echo.Context, doc interface{}) error
}

type MiddlewareHandler

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

type RepositoryBase

type RepositoryBase struct {
	Driver db.DatabaseBase
}

func (*RepositoryBase) Init

func (r *RepositoryBase) Init(driver db.DatabaseBase)

type RepositoryInterface

type RepositoryInterface interface {
	EnsureIndexs()
}

type RouterBase

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

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

Jump to

Keyboard shortcuts

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