Path Parameter Types
Iris provides the easiest and the most powerful routing process you have ever experienced.
Iris has its own interpreter for route’s path syntax, which can parse and evaluate complex expressions (yes, like a programming language!).
It’s fast, because it optimizes its routing based on the needs of each route. If no special regexp is needed, it registers the route with the low-level path syntax. If regexp is needed, it pre-compiles it and adds the necessary middleware(s). That means that you have zero performance cost compared to other routers or web frameworks.
Parameters
A path parameter's name should contain only alphabetical letters. Numbers or symbols like '_' are NOT allowed.
Do not confuse ctx.Params()
with ctx.Values()
.
Path parameter's values can be retrieved from
ctx.Params()
.Context's local storage that can be used to communicate between handlers and middleware(s) can be stored to
ctx.Values()
.
The built-in available parameter types can be found at the following table.
:string
string
anything (single path segment)
Params().Get
:uuid
string
uuidv4 or v1 (single path segment)
Params().Get
:int
int
-9223372036854775808 to 9223372036854775807 (x64) or -2147483648 to 2147483647 (x32), depends on the host arch
Params().GetInt
:int8
int8
-128 to 127
Params().GetInt8
:int16
int16
-32768 to 32767
Params().GetInt16
:int32
int32
-2147483648 to 2147483647
Params().GetInt32
:int64
int64
-9223372036854775808 to 9223372036854775807
Params().GetInt64
:uint
uint
0 to 18446744073709551615 (x64) or 0 to 4294967295 (x32), depends on the host arch
Params().GetUint
:uint8
uint8
0 to 255
Params().GetUint8
:uint16
uint16
0 to 65535
Params().GetUint16
:uint32
uint32
0 to 4294967295
Params().GetUint32
:uint64
uint64
0 to 18446744073709551615
Params().GetUint64
:bool
bool
"1" or "t" or "T" or "TRUE" or "true" or "True" or "0" or "f" or "F" or "FALSE" or "false" or "False"
Params().GetBool
:alphabetical
string
lowercase or uppercase letters
Params().Get
:file
string
lowercase or uppercase letters, numbers, underscore (_), dash (-), point (.) and no spaces or other special characters that are not valid for filenames
Params().Get
:path
string
anything, can be separated by slashes (path segments) but should be the last part of the route path
Params().Get
:uuid
string
uuidv4 (and v1) path parameter validation
Params().Get
:mail
string
email without domain validation
Params().Get
:email
string
email with domain validation
Params().Get
:date
string
yyyy/mm/dd format e.g. /blog/{param:date} matches /blog/2022/04/21
`Params().SimpleDate(
:weekday
uint or string
0-6 positive integer or longname format ("sunday" to "monday" or "Sunday" to "Monday")
Params().GetWeekday
Usage:
regexp
(expr string)
:string
prefix
(prefix string)
:string
suffix
(suffix string)
:string
contains
(s string)
:string
min
(minValue int or int8 or int16 or int32 or int64 or uint8 or uint16 or uint32 or uint64 or float32 or float64)
:string(char length), :int, :int8, :int16, :int32, :int64, :uint, :uint8, :uint16, :uint32, :uint64
max
(maxValue int or int8 or int16 or int32 or int64 or uint8 or uint16 or uint32 or uint64 or float32 or float64)
:string(char length), :int, :int8, :int16, :int32, :int64, :uint, :uint8, :uint16, :uint32, :uint64
range
(minValue, maxValue int or int8 or int16 or int32 or int64 or uint8 or uint16 or uint32 or uint64 or float32 or float64)
:int, :int8, :int16, :int32, :int64, :uint, :uint8, :uint16, :uint32, :uint64
Usage:
Do It Yourself:
The RegisterFunc
can accept any function that returns a func(paramValue string) bool
. Or just a func(string) bool
. If the validation fails then it will fire 404
or whatever status code the else
keyword has.
Register your custom macro function which accepts two int arguments.
Register your custom macro function which accepts a slice of strings [...,...]
.
Example Code:
When parameter type is missing then it defaults to the
string
one, therefore{name:string}
and{name}
refers to the same exactly thing.
Last updated