2017-03-27 03:09:44 +02:00
|
|
|
package ast
|
|
|
|
|
2018-09-26 10:37:11 +02:00
|
|
|
type (
|
|
|
|
// ParamType holds the necessary information about a parameter type for the parser to lookup for.
|
|
|
|
ParamType interface {
|
|
|
|
// The name of the parameter type.
|
|
|
|
// Indent should contain the characters for the parser.
|
|
|
|
Indent() string
|
|
|
|
}
|
2017-03-27 03:09:44 +02:00
|
|
|
|
2018-09-26 10:37:11 +02:00
|
|
|
// MasterParamType if implemented and its `Master()` returns true then empty type param will be translated to this param type.
|
|
|
|
// Also its functions will be available to the rest of the macro param type's funcs.
|
|
|
|
//
|
|
|
|
// Only one Master is allowed.
|
|
|
|
MasterParamType interface {
|
|
|
|
ParamType
|
|
|
|
Master() 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
|
|
|
|
2018-09-26 10:37:11 +02:00
|
|
|
// TrailingParamType if implemented and its `Trailing()` returns true
|
|
|
|
// then it should be declared at the end of a route path and can accept any trailing path segment as one parameter.
|
|
|
|
TrailingParamType interface {
|
|
|
|
ParamType
|
|
|
|
Trailing() bool
|
|
|
|
}
|
2017-12-04 04:06:03 +01:00
|
|
|
|
2018-09-26 10:37:11 +02:00
|
|
|
// AliasParamType if implemeneted nad its `Alias()` returns a non-empty string
|
|
|
|
// then the param type can be written with that string literal too.
|
|
|
|
AliasParamType interface {
|
|
|
|
ParamType
|
|
|
|
Alias() string
|
|
|
|
}
|
|
|
|
)
|
2017-11-23 11:30:13 +01:00
|
|
|
|
2018-09-26 10:37:11 +02:00
|
|
|
// IsMaster returns true if the "pt" param type is a master one.
|
|
|
|
func IsMaster(pt ParamType) bool {
|
|
|
|
p, ok := pt.(MasterParamType)
|
|
|
|
return ok && p.Master()
|
2017-11-02 04:54:33 +01:00
|
|
|
}
|
|
|
|
|
2018-09-26 10:37:11 +02:00
|
|
|
// IsTrailing returns true if the "pt" param type is a marked as trailing,
|
|
|
|
// which should accept more than one path segment when in the end.
|
|
|
|
func IsTrailing(pt ParamType) bool {
|
|
|
|
p, ok := pt.(TrailingParamType)
|
|
|
|
return ok && p.Trailing()
|
2017-12-04 04:06:03 +01:00
|
|
|
}
|
|
|
|
|
2018-09-26 10:37:11 +02:00
|
|
|
// HasAlias returns any alias of the "pt" param type.
|
|
|
|
// If alias is empty or not found then it returns false as its second output argument.
|
|
|
|
func HasAlias(pt ParamType) (string, bool) {
|
|
|
|
if p, ok := pt.(AliasParamType); ok {
|
|
|
|
alias := p.Alias()
|
|
|
|
return alias, len(alias) > 0
|
|
|
|
}
|
|
|
|
|
|
|
|
return "", false
|
2017-11-02 04:54:33 +01:00
|
|
|
}
|
|
|
|
|
2018-09-26 10:37:11 +02:00
|
|
|
// GetMasterParamType accepts a list of ParamType and returns its master.
|
|
|
|
// If no `Master` specified:
|
2018-09-01 17:53:42 +02:00
|
|
|
// and len(paramTypes) > 0 then it will return the first one,
|
2018-09-26 10:37:11 +02:00
|
|
|
// otherwise it returns nil.
|
|
|
|
func GetMasterParamType(paramTypes ...ParamType) ParamType {
|
2018-09-01 17:53:42 +02:00
|
|
|
for _, pt := range paramTypes {
|
2018-09-26 10:37:11 +02:00
|
|
|
if IsMaster(pt) {
|
2018-09-01 17:53:42 +02:00
|
|
|
return pt
|
|
|
|
}
|
|
|
|
}
|
2018-08-23 05:30:12 +02:00
|
|
|
|
2018-09-01 17:53:42 +02:00
|
|
|
if len(paramTypes) > 0 {
|
|
|
|
return paramTypes[0]
|
|
|
|
}
|
2018-08-23 05:30:12 +02:00
|
|
|
|
2018-09-26 10:37:11 +02:00
|
|
|
return nil
|
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
|
|
|
// LookupParamType accepts the string
|
|
|
|
// representation of a parameter type.
|
2018-09-26 10:37:11 +02:00
|
|
|
// Example:
|
2017-06-12 03:47:16 +02:00
|
|
|
// "string"
|
2018-08-23 05:30:12 +02:00
|
|
|
// "number" or "int"
|
|
|
|
// "long" or "int64"
|
2018-08-23 23:56:54 +02:00
|
|
|
// "uint8"
|
2018-08-23 05:30:12 +02:00
|
|
|
// "uint64"
|
|
|
|
// "boolean" or "bool"
|
2017-06-12 03:47:16 +02:00
|
|
|
// "alphabetical"
|
|
|
|
// "file"
|
|
|
|
// "path"
|
2018-09-26 10:37:11 +02:00
|
|
|
func LookupParamType(indentOrAlias string, paramTypes ...ParamType) (ParamType, bool) {
|
2018-09-01 17:53:42 +02:00
|
|
|
for _, pt := range paramTypes {
|
2018-09-26 10:37:11 +02:00
|
|
|
if pt.Indent() == indentOrAlias {
|
2018-09-01 17:53:42 +02:00
|
|
|
return pt, true
|
|
|
|
}
|
|
|
|
|
2018-09-26 10:37:11 +02:00
|
|
|
if alias, has := HasAlias(pt); has {
|
|
|
|
if alias == indentOrAlias {
|
2018-09-01 17:53:42 +02:00
|
|
|
return pt, true
|
|
|
|
}
|
|
|
|
}
|
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-01 17:53:42 +02:00
|
|
|
|
2018-09-26 10:37:11 +02:00
|
|
|
return nil, false
|
2017-12-04 04:06:03 +01:00
|
|
|
}
|
|
|
|
|
2017-06-12 03:47:16 +02:00
|
|
|
// ParamStatement is a struct
|
|
|
|
// which holds all the necessary information about a macro parameter.
|
|
|
|
// It holds its type (string, int, alphabetical, file, path),
|
|
|
|
// its source ({param:type}),
|
|
|
|
// its name ("param"),
|
|
|
|
// its attached functions by the user (min, max...)
|
|
|
|
// and the http error code if that parameter
|
|
|
|
// failed to be evaluated.
|
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 ParamStatement struct {
|
|
|
|
Src string // the original unparsed source, i.e: {id:int range(1,5) else 404}
|
|
|
|
Name string // id
|
|
|
|
Type ParamType // int
|
|
|
|
Funcs []ParamFunc // range
|
|
|
|
ErrorCode int // 404
|
|
|
|
}
|
|
|
|
|
2017-06-12 03:47:16 +02:00
|
|
|
// ParamFunc holds the name of a parameter's function
|
|
|
|
// and its arguments (values)
|
|
|
|
// A param func is declared with:
|
|
|
|
// {param:int range(1,5)},
|
|
|
|
// the range is the
|
|
|
|
// param function name
|
|
|
|
// the 1 and 5 are the two param function arguments
|
2017-03-27 03:09:44 +02:00
|
|
|
// range(1,5)
|
|
|
|
type ParamFunc struct {
|
2018-08-23 16:29:39 +02:00
|
|
|
Name string // range
|
|
|
|
Args []string // ["1","5"]
|
2017-03-27 03:09:44 +02:00
|
|
|
}
|