Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
package macro
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"reflect"
|
|
|
|
"regexp"
|
2017-09-07 15:20:31 +02:00
|
|
|
"strconv"
|
2018-08-23 16:29:39 +02:00
|
|
|
"strings"
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
"unicode"
|
|
|
|
)
|
|
|
|
|
2017-06-12 03:47:16 +02:00
|
|
|
// 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.
|
2018-09-27 02:17:45 +02:00
|
|
|
// type EvaluatorFunc func(paramValue string) bool
|
|
|
|
// type BinderFunc func(paramValue string) interface{}
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
|
2018-09-27 02:17:45 +02:00
|
|
|
type (
|
|
|
|
ParamEvaluator func(paramValue string) (interface{}, bool)
|
|
|
|
// FuncEvaluator interface{} // i.e func(paramValue int) bool
|
|
|
|
)
|
|
|
|
|
|
|
|
var goodEvaluatorFuncs = []reflect.Type{
|
|
|
|
reflect.TypeOf(func(string) (interface{}, bool) { return nil, false }),
|
|
|
|
reflect.TypeOf(ParamEvaluator(func(string) (interface{}, bool) { return nil, false })),
|
|
|
|
}
|
|
|
|
|
|
|
|
func goodParamFunc(typ reflect.Type) bool {
|
|
|
|
if typ.Kind() == reflect.Func { // it should be a func which returns a func (see below check).
|
|
|
|
if typ.NumOut() == 1 {
|
|
|
|
typOut := typ.Out(0)
|
|
|
|
if typOut.Kind() != reflect.Func {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if typOut.NumOut() == 2 { // if it's a type of EvaluatorFunc, used for param evaluator.
|
|
|
|
for _, fType := range goodEvaluatorFuncs {
|
|
|
|
if typOut == fType {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if typOut.NumIn() == 1 && typOut.NumOut() == 1 { // if it's a type of func(paramValue [int,string...]) bool, used for param funcs.
|
|
|
|
return typOut.Out(0).Kind() == reflect.Bool
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Regexp accepts a regexp "expr" expression
|
|
|
|
// and returns its MatchString.
|
|
|
|
// The regexp is compiled before return.
|
2017-06-12 03:47:16 +02:00
|
|
|
//
|
|
|
|
// Returns a not-nil error on regexp compile failure.
|
2018-09-27 02:17:45 +02:00
|
|
|
func Regexp(expr string) (func(string) bool, error) {
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
if expr == "" {
|
|
|
|
return nil, fmt.Errorf("empty regex expression")
|
|
|
|
}
|
|
|
|
|
|
|
|
// add the last $ if missing (and not wildcard(?))
|
|
|
|
if i := expr[len(expr)-1]; i != '$' && i != '*' {
|
|
|
|
expr += "$"
|
|
|
|
}
|
|
|
|
|
|
|
|
r, err := regexp.Compile(expr)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return r.MatchString, nil
|
|
|
|
}
|
|
|
|
|
2018-09-27 02:17:45 +02:00
|
|
|
// MustRegexp same as Regexp
|
2017-06-12 03:47:16 +02:00
|
|
|
// but it panics on the "expr" parse failure.
|
2018-09-27 02:17:45 +02:00
|
|
|
func MustRegexp(expr string) func(string) bool {
|
|
|
|
r, err := Regexp(expr)
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
|
|
|
// goodParamFuncName reports whether the function name is a valid identifier.
|
|
|
|
func goodParamFuncName(name string) bool {
|
|
|
|
if name == "" {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
// valid names are only letters and _
|
|
|
|
for _, r := range name {
|
|
|
|
switch {
|
|
|
|
case r == '_':
|
|
|
|
case !unicode.IsLetter(r):
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// the convertBuilderFunc return value is generating at boot time.
|
|
|
|
// convertFunc converts an interface to a valid full param function.
|
2018-09-27 02:17:45 +02:00
|
|
|
func convertBuilderFunc(fn interface{}) ParamFuncBuilder {
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
|
|
|
|
typFn := reflect.TypeOf(fn)
|
|
|
|
if !goodParamFunc(typFn) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
numFields := typFn.NumIn()
|
|
|
|
|
2018-09-27 02:17:45 +02:00
|
|
|
return func(args []string) reflect.Value {
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
if len(args) != numFields {
|
|
|
|
// no variadics support, for now.
|
|
|
|
panic("args should be the same len as numFields")
|
|
|
|
}
|
|
|
|
var argValues []reflect.Value
|
|
|
|
for i := 0; i < numFields; i++ {
|
|
|
|
field := typFn.In(i)
|
|
|
|
arg := args[i]
|
|
|
|
|
2018-08-23 16:29:39 +02:00
|
|
|
// try to convert the string literal as we get it from the parser.
|
|
|
|
var (
|
2018-09-26 10:37:11 +02:00
|
|
|
val interface{}
|
|
|
|
|
|
|
|
panicIfErr = func(err error) {
|
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Sprintf("on field index: %d: %v", i, err))
|
|
|
|
}
|
|
|
|
}
|
2018-08-23 16:29:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// try to get the value based on the expected type.
|
|
|
|
switch field.Kind() {
|
|
|
|
case reflect.Int:
|
2018-09-26 10:37:11 +02:00
|
|
|
v, err := strconv.Atoi(arg)
|
|
|
|
panicIfErr(err)
|
|
|
|
val = v
|
2018-08-23 16:29:39 +02:00
|
|
|
case reflect.Int8:
|
2018-09-26 10:37:11 +02:00
|
|
|
v, err := strconv.ParseInt(arg, 10, 8)
|
|
|
|
panicIfErr(err)
|
|
|
|
val = int8(v)
|
2018-08-23 16:29:39 +02:00
|
|
|
case reflect.Int16:
|
2018-09-26 10:37:11 +02:00
|
|
|
v, err := strconv.ParseInt(arg, 10, 16)
|
|
|
|
panicIfErr(err)
|
|
|
|
val = int16(v)
|
2018-08-23 16:29:39 +02:00
|
|
|
case reflect.Int32:
|
2018-09-26 10:37:11 +02:00
|
|
|
v, err := strconv.ParseInt(arg, 10, 32)
|
|
|
|
panicIfErr(err)
|
|
|
|
val = int32(v)
|
2018-08-23 16:29:39 +02:00
|
|
|
case reflect.Int64:
|
2018-09-26 10:37:11 +02:00
|
|
|
v, err := strconv.ParseInt(arg, 10, 64)
|
|
|
|
panicIfErr(err)
|
|
|
|
val = v
|
2018-09-27 05:20:03 +02:00
|
|
|
case reflect.Uint:
|
|
|
|
v, err := strconv.ParseUint(arg, 10, strconv.IntSize)
|
|
|
|
panicIfErr(err)
|
|
|
|
val = uint(v)
|
2018-08-23 16:29:39 +02:00
|
|
|
case reflect.Uint8:
|
2018-09-26 10:37:11 +02:00
|
|
|
v, err := strconv.ParseUint(arg, 10, 8)
|
|
|
|
panicIfErr(err)
|
|
|
|
val = uint8(v)
|
2018-08-23 16:29:39 +02:00
|
|
|
case reflect.Uint16:
|
2018-09-26 10:37:11 +02:00
|
|
|
v, err := strconv.ParseUint(arg, 10, 16)
|
|
|
|
panicIfErr(err)
|
|
|
|
val = uint16(v)
|
2018-08-23 16:29:39 +02:00
|
|
|
case reflect.Uint32:
|
2018-09-26 10:37:11 +02:00
|
|
|
v, err := strconv.ParseUint(arg, 10, 32)
|
|
|
|
panicIfErr(err)
|
|
|
|
val = uint32(v)
|
2018-08-23 16:29:39 +02:00
|
|
|
case reflect.Uint64:
|
2018-09-26 10:37:11 +02:00
|
|
|
v, err := strconv.ParseUint(arg, 10, 64)
|
|
|
|
panicIfErr(err)
|
|
|
|
val = v
|
2018-08-23 16:29:39 +02:00
|
|
|
case reflect.Float32:
|
2018-09-26 10:37:11 +02:00
|
|
|
v, err := strconv.ParseFloat(arg, 32)
|
|
|
|
panicIfErr(err)
|
|
|
|
val = float32(v)
|
2018-08-23 16:29:39 +02:00
|
|
|
case reflect.Float64:
|
2018-09-26 10:37:11 +02:00
|
|
|
v, err := strconv.ParseFloat(arg, 64)
|
|
|
|
panicIfErr(err)
|
|
|
|
val = v
|
2018-08-23 16:29:39 +02:00
|
|
|
case reflect.Bool:
|
2018-09-26 10:37:11 +02:00
|
|
|
v, err := strconv.ParseBool(arg)
|
|
|
|
panicIfErr(err)
|
|
|
|
val = v
|
2018-08-23 16:29:39 +02:00
|
|
|
case reflect.Slice:
|
|
|
|
if len(arg) > 1 {
|
|
|
|
if arg[0] == '[' && arg[len(arg)-1] == ']' {
|
|
|
|
// it is a single argument but as slice.
|
2018-09-26 10:37:11 +02:00
|
|
|
val = strings.Split(arg[1:len(arg)-1], ",") // only string slices.
|
2018-08-23 16:29:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
2018-09-26 10:37:11 +02:00
|
|
|
val = arg
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
}
|
|
|
|
|
2018-09-26 10:37:11 +02:00
|
|
|
argValue := reflect.ValueOf(val)
|
2018-08-23 16:29:39 +02:00
|
|
|
if expected, got := field.Kind(), argValue.Kind(); expected != got {
|
2018-09-27 02:17:45 +02:00
|
|
|
panic(fmt.Sprintf("func's input arguments should have the same type: [%d] expected %s but got %s", i, expected, got))
|
2018-08-23 16:29:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
argValues = append(argValues, argValue)
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
}
|
|
|
|
|
2018-09-27 02:17:45 +02:00
|
|
|
evalFn := reflect.ValueOf(fn).Call(argValues)[0]
|
|
|
|
|
|
|
|
// var evaluator EvaluatorFunc
|
|
|
|
// // check for typed and not typed
|
|
|
|
// if _v, ok := evalFn.(EvaluatorFunc); ok {
|
|
|
|
// evaluator = _v
|
|
|
|
// } else if _v, ok = evalFn.(func(string) bool); ok {
|
|
|
|
// evaluator = _v
|
|
|
|
// }
|
|
|
|
// return func(paramValue interface{}) bool {
|
|
|
|
// return evaluator(paramValue)
|
|
|
|
// }
|
|
|
|
return evalFn
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type (
|
2017-06-12 03:47:16 +02:00
|
|
|
// 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.
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
Macro struct {
|
2018-09-26 10:37:11 +02:00
|
|
|
indent string
|
|
|
|
alias string
|
|
|
|
master bool
|
|
|
|
trailing bool
|
|
|
|
|
2018-09-27 02:17:45 +02:00
|
|
|
Evaluator ParamEvaluator
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
funcs []ParamFunc
|
|
|
|
}
|
|
|
|
|
2018-09-27 02:17:45 +02:00
|
|
|
// ParamFuncBuilder is a func
|
2017-06-12 03:47:16 +02:00
|
|
|
// which accepts a param function's arguments (values)
|
2018-09-27 02:17:45 +02:00
|
|
|
// and returns a function as value, its job
|
2017-06-12 03:47:16 +02:00
|
|
|
// is to make the macros to be registered
|
|
|
|
// by user at the most generic possible way.
|
2018-09-27 05:20:03 +02:00
|
|
|
ParamFuncBuilder func([]string) reflect.Value // the func(<T>) bool
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
|
2017-06-12 03:47:16 +02:00
|
|
|
// ParamFunc represents the parsed
|
|
|
|
// parameter function, it holds
|
|
|
|
// the parameter's name
|
|
|
|
// and the function which will build
|
|
|
|
// the evaluator func.
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
ParamFunc struct {
|
|
|
|
Name string
|
2018-09-27 02:17:45 +02:00
|
|
|
Func ParamFuncBuilder
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2018-09-26 10:37:11 +02:00
|
|
|
// NewMacro creates and returns a Macro that can be used as a registry for
|
|
|
|
// a new customized parameter type and its functions.
|
2018-09-27 02:17:45 +02:00
|
|
|
func NewMacro(indent, alias string, master, trailing bool, evaluator ParamEvaluator) *Macro {
|
2018-09-26 10:37:11 +02:00
|
|
|
return &Macro{
|
|
|
|
indent: indent,
|
|
|
|
alias: alias,
|
|
|
|
master: master,
|
|
|
|
trailing: trailing,
|
|
|
|
|
|
|
|
Evaluator: evaluator,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Macro) Indent() string {
|
|
|
|
return m.indent
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Macro) Alias() string {
|
|
|
|
return m.alias
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Macro) Master() bool {
|
|
|
|
return m.master
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
}
|
|
|
|
|
2018-09-26 10:37:11 +02:00
|
|
|
func (m *Macro) Trailing() bool {
|
|
|
|
return m.trailing
|
|
|
|
}
|
|
|
|
|
|
|
|
// func (m *Macro) SetParamResolver(fn func(memstore.Entry) interface{}) *Macro {
|
|
|
|
// m.ParamResolver = fn
|
|
|
|
// return m
|
|
|
|
// }
|
|
|
|
|
2017-06-12 03:47:16 +02:00
|
|
|
// 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){})
|
2018-09-26 10:37:11 +02:00
|
|
|
func (m *Macro) RegisterFunc(funcName string, fn interface{}) *Macro {
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
fullFn := convertBuilderFunc(fn)
|
|
|
|
m.registerFunc(funcName, fullFn)
|
2018-09-26 10:37:11 +02:00
|
|
|
|
|
|
|
return m
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
}
|
|
|
|
|
2018-09-27 02:17:45 +02:00
|
|
|
func (m *Macro) registerFunc(funcName string, fullFn ParamFuncBuilder) {
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
if !goodParamFuncName(funcName) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, fn := range m.funcs {
|
|
|
|
if fn.Name == funcName {
|
|
|
|
fn.Func = fullFn
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m.funcs = append(m.funcs, ParamFunc{
|
|
|
|
Name: funcName,
|
|
|
|
Func: fullFn,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-09-27 02:17:45 +02:00
|
|
|
func (m *Macro) getFunc(funcName string) ParamFuncBuilder {
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
for _, fn := range m.funcs {
|
|
|
|
if fn.Name == funcName {
|
|
|
|
if fn.Func == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
return fn.Func
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|