macro

package
v10.7.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2018 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EvaluatorFunc

type EvaluatorFunc func(paramValue string) bool

EvaluatorFunc is the signature for both param types and param funcs. It should accepts the param's value as string and return true if validated otherwise false.

func MustNewEvaluatorFromRegexp

func MustNewEvaluatorFromRegexp(expr string) EvaluatorFunc

MustNewEvaluatorFromRegexp same as NewEvaluatorFromRegexp but it panics on the "expr" parse failure.

func NewEvaluatorFromRegexp

func NewEvaluatorFromRegexp(expr string) (EvaluatorFunc, error)

NewEvaluatorFromRegexp accepts a regexp "expr" expression and returns an EvaluatorFunc based on that regexp. the regexp is compiled before return.

Returns a not-nil error on regexp compile failure.

type Macro

type Macro struct {
	Evaluator EvaluatorFunc
	// contains filtered or unexported fields
}

Macro represents the parsed macro, which holds the evaluator (param type's evaluator + param functions evaluators) and its param functions.

Any type contains its own macro instance, so an String type contains its type evaluator which is the "Evaluator" field and it can register param functions to that macro which maps to a parameter type.

func (*Macro) RegisterFunc

func (m *Macro) RegisterFunc(funcName string, fn interface{})

RegisterFunc registers a parameter function to that macro. Accepts the func name ("range") and the function body, which should return an EvaluatorFunc a bool (it will be converted to EvaluatorFunc later on), i.e RegisterFunc("min", func(minValue int) func(paramValue string) bool){})

type Map

type Map struct {
	// string type
	// anything
	String *Macro
	// uint type
	// only positive numbers (+0-9)
	// it could be uint/uint32 but we keep int for simplicity
	Int *Macro
	// long an int64 type
	// only positive numbers (+0-9)
	// it could be uint64 but we keep int64 for simplicity
	Long *Macro
	// boolean as bool type
	// a string which is "1" or "t" or "T" or "TRUE" or "true" or "True"
	// or "0" or "f" or "F" or "FALSE" or "false" or "False".
	Boolean *Macro
	// alphabetical/letter type
	// letters only (upper or lowercase)
	Alphabetical *Macro
	// file type
	// letters (upper or lowercase)
	// numbers (0-9)
	// underscore (_)
	// dash (-)
	// point (.)
	// no spaces! or other character
	File *Macro
	// path type
	// anything, should be the last part
	Path *Macro
}

Map contains the default macros mapped to their types. This is the manager which is used by the caller to register custom parameter functions per param-type (String, Int, Long, Boolean, Alphabetical, File, Path).

func NewMap

func NewMap() *Map

NewMap returns a new macro Map with default type evaluators.

Learn more at: https://github.com/kataras/iris/tree/master/_examples/routing/dynamic-path

func (*Map) Lookup

func (m *Map) Lookup(typ ast.ParamType) *Macro

Lookup returns the specific Macro from the map based on the parameter type. i.e if ast.ParamTypeInt then it will return the m.Int. Returns the m.String if not matched.

type ParamEvaluatorBuilder

type ParamEvaluatorBuilder func([]ast.ParamFuncArg) EvaluatorFunc

ParamEvaluatorBuilder is a func which accepts a param function's arguments (values) and returns an EvaluatorFunc, its job is to make the macros to be registered by user at the most generic possible way.

type ParamFunc

type ParamFunc struct {
	Name string
	Func ParamEvaluatorBuilder
}

ParamFunc represents the parsed parameter function, it holds the parameter's name and the function which will build the evaluator func.

type Template

type Template struct {
	// Src is the original template given by the client
	Src    string          `json:"src"`
	Params []TemplateParam `json:"params"`
}

Template contains a route's path full parsed template.

Fields: Src is the raw source of the path, i.e /users/{id:int min(1)} Params is the list of the Params that are being used to the path, i.e the min as param name and 1 as the param argument.

func Parse

func Parse(src string, macros *Map) (*Template, error)

Parse takes a full route path and a macro map (macro map contains the macro types with their registered param functions) and returns a new Template. It builds all the parameter functions for that template and their evaluators, it's the api call that makes use the interpeter's parser -> lexer.

type TemplateParam

type TemplateParam struct {
	Src string `json:"src"` // the unparsed param'false source
	// Type is not useful anywhere here but maybe
	// it's useful on host to decide how to convert the path template to specific router's syntax
	Type          ast.ParamType   `json:"type"`
	Name          string          `json:"name"`
	ErrCode       int             `json:"errCode"`
	TypeEvaluator EvaluatorFunc   `json:"-"`
	Funcs         []EvaluatorFunc `json:"-"`
}

TemplateParam is the parsed macro parameter's template they are being used to describe the param's syntax result.

Directories

Path Synopsis
interpreter
ast

Jump to

Keyboard shortcuts

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