check

package
v0.0.0-...-0c811c1 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Build BuildFunc

	// code 4xx
	ErrNotRESTfulRequest = errors.New("method not in POST/DELETE/GET/PUT")

	// code 5xx
	ErrBuildConfig   = errors.New("config for BuildFunc is error")
	ErrRuleWrong     = errors.New("param check rule wrong")
	ErrAuthLoadCrash = errors.New("auto load crash")
)

for init

View Source
var (
	PccEmptyStr = &PCC{DefaultV: []string{""}}
	PccMust     = &PCC{Must: true}
)

PCC in common use

View Source
var NoMust = new(Must)

NoMust Check

View Source
var (
	PmInt = func(ps []string) (interface{}, error) {
		return strconv.Atoi(ps[0])
	}
)

ParamModify in common use

Functions

This section is empty.

Types

type BaseLoader

type BaseLoader struct {
	Err error
	// contains filtered or unexported fields
}

BaseLoader for entity

func (*BaseLoader) Load

func (b *BaseLoader) Load(es ...interface{}) error

Load for entity

type BaseRuleBuilder

type BaseRuleBuilder struct {
	// Request
	Params url.Values // 参数值可以重名,但是大部分时候默认只看第一个

	// Result
	Err error
}

BaseRuleBuilder for check preparation

func (*BaseRuleBuilder) Rules

func (b *BaseRuleBuilder) Rules(m *Must, pcms ...PCM) Loader

Rules Checking

type BuildFunc

type BuildFunc func(interface{}) RuleBuilder

BuildFunc for init

type ErrParamWrong

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

ErrParamWrong in check

code 4xx

func NewErrParamWrong

func NewErrParamWrong(name, msg string) ErrParamWrong

NewErrParamWrong Builder

func (ErrParamWrong) Error

func (e ErrParamWrong) Error() string

type Flow

type Flow struct {
	Params map[string]*api.Pair
}

type Loader

type Loader interface {
	Load(...interface{}) error
}

Loader for params

type Logical

type Logical int

Logical for check

const (
	LogicalAnd Logical = iota
	LogicalOr
)

Logical(s)

type Middleware

type Middleware func(ctx context.Context, s *Flow) error

func ParamAutoLoad

func ParamAutoLoad(modify ParamModifyList, entity interface{}) Middleware

ParamAutoLoad Wrapper

func ParamCheck

func ParamCheck(pccs PCCS) Middleware

ParamCheck Wrapper

type Model

type Model map[string]interface{}

Model for check

type Must

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

Must Check

func M

func M(ks ...string) *Must

M ust

func (*Must) And

func (m *Must) And(o *Must) *Must

And logical

func (*Must) Multi

func (m *Must) Multi() *Must

Multi logical

func (*Must) Or

func (m *Must) Or(o *Must) *Must

Or logical

func (*Must) Test

func (m *Must) Test(vs url.Values) (Model, error)

Test Params

type PCC

type PCC struct {
	Must     bool
	Multi    bool
	DefaultV []string

	Link        string
	LinkLogical Logical

	Rename string
	// contains filtered or unexported fields
}

PCC - ParamCheck Config

func PccLabel

func PccLabel(pcc *PCC, logical Logical) *PCC

PccLabel Builder

func PccLink(label string) *PCC

PccLink Builder

func PccRename

func PccRename(pcc *PCC, name string) *PCC

PccRename Builder

type PCCS

type PCCS map[string]*PCC

PCCS - PCC Group

type PCM

type PCM func(Model) error

PCM - ParamCheck Middleware

func Atoi

func Atoi(k string) PCM

Atoi - param is change to Int

func DefaultValue

func DefaultValue(k, v string) PCM

DefaultValue PCM

func Rename

func Rename(o, n string) PCM

Rename PCM

type ParamModify

type ParamModify func([]string) (interface{}, error)

ParamModify for ParamAutoLoad

type ParamModifyList

type ParamModifyList map[string]ParamModify

ParamModifyList for ParamAutoLoad

type RuleBuilder

type RuleBuilder interface {
	Rules(*Must, ...PCM) Loader
}

RuleBuilder for check preparation

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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