mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 10:41:03 +01:00
add the new param:long into the docs
Former-commit-id: a4189660ad6228b5d3e118ef0f03a52972ac03ad
This commit is contained in:
parent
f68e547fb6
commit
59a61e5930
|
@ -23,7 +23,7 @@ func main() {
|
||||||
// At the same time,
|
// At the same time,
|
||||||
// iris has its own interpeter(yes like a programming language)
|
// iris has its own interpeter(yes like a programming language)
|
||||||
// for route's path syntax and their dynamic path parameters parsing and evaluation,
|
// for route's path syntax and their dynamic path parameters parsing and evaluation,
|
||||||
// I am calling them "macros" for shortcut.
|
// We call them "macros" for shortcut.
|
||||||
// How? It calculates its needs and if not any special regexp needed then it just
|
// How? It calculates its needs and if not any special regexp needed then it just
|
||||||
// registers the route with the low-level underline path syntax,
|
// registers the route with the low-level underline path syntax,
|
||||||
// otherwise it pre-compiles the regexp and adds the necessary middleware(s).
|
// otherwise it pre-compiles the regexp and adds the necessary middleware(s).
|
||||||
|
@ -41,6 +41,12 @@ func main() {
|
||||||
// int type
|
// int type
|
||||||
// only numbers (0-9)
|
// only numbers (0-9)
|
||||||
//
|
//
|
||||||
|
// +------------------------+
|
||||||
|
// | {param:long} |
|
||||||
|
// +------------------------+
|
||||||
|
// int64 type
|
||||||
|
// only numbers (0-9)
|
||||||
|
//
|
||||||
// +------------------------+
|
// +------------------------+
|
||||||
// | {param:alphabetical} |
|
// | {param:alphabetical} |
|
||||||
// +------------------------+
|
// +------------------------+
|
||||||
|
@ -63,14 +69,12 @@ func main() {
|
||||||
// +------------------------+
|
// +------------------------+
|
||||||
// path type
|
// path type
|
||||||
// anything, should be the last part, more than one path segment,
|
// anything, should be the last part, more than one path segment,
|
||||||
// i.e: /path1/path2/path3 , ctx.Params().GetString("param") == "/path1/path2/path3"
|
// i.e: /path1/path2/path3 , ctx.Params().Get("param") == "/path1/path2/path3"
|
||||||
//
|
//
|
||||||
// if type is missing then parameter's type is defaulted to string, so
|
// if type is missing then parameter's type is defaulted to string, so
|
||||||
// {param} == {param:string}.
|
// {param} == {param:string}.
|
||||||
//
|
//
|
||||||
// If a function not found on that type then the "string"'s types functions are being used.
|
// If a function not found on that type then the `string` macro type's functions are being used.
|
||||||
// i.e:
|
|
||||||
// {param:int min(3)}
|
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// Besides the fact that iris provides the basic types and some default "macro funcs"
|
// Besides the fact that iris provides the basic types and some default "macro funcs"
|
||||||
|
@ -167,16 +171,10 @@ func main() {
|
||||||
// if "/mypath/{myparam:path}" then the parameter has two names, one is the "*" and the other is the user-defined "myparam".
|
// if "/mypath/{myparam:path}" then the parameter has two names, one is the "*" and the other is the user-defined "myparam".
|
||||||
|
|
||||||
// WARNING:
|
// WARNING:
|
||||||
// A path parameter name should contain only alphabetical letters, symbols, containing '_' and numbers are NOT allowed.
|
// A path parameter name should contain only alphabetical letters. Symbols like '_' and numbers are NOT allowed.
|
||||||
// If route failed to be registered, the app will panic without any warnings
|
// Last, do not confuse `ctx.Params()` with `ctx.Values()`.
|
||||||
// if you didn't catch the second return value(error) on .Handle/.Get....
|
// Path parameter's values goes to `ctx.Params()` and context's local storage
|
||||||
|
|
||||||
// Last, do not confuse ctx.Values() with ctx.Params().
|
|
||||||
// Path parameter's values goes to ctx.Params() and context's local storage
|
|
||||||
// that can be used to communicate between handlers and middleware(s) goes to
|
// that can be used to communicate between handlers and middleware(s) goes to
|
||||||
// ctx.Values(), path parameters and the rest of any custom values are separated for your own good.
|
// `ctx.Values()`.
|
||||||
|
app.Run(iris.Addr(":8080"))
|
||||||
if err := app.Run(iris.Addr(":8080")); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
38
doc.go
38
doc.go
|
@ -682,7 +682,7 @@ MVC - Model View Controller
|
||||||
Iris has first-class support for the MVC pattern, you'll not find
|
Iris has first-class support for the MVC pattern, you'll not find
|
||||||
these stuff anywhere else in the Go world.
|
these stuff anywhere else in the Go world.
|
||||||
|
|
||||||
Example Code
|
Example Code:
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
@ -865,7 +865,7 @@ Parameterized Path
|
||||||
|
|
||||||
At the previous example,
|
At the previous example,
|
||||||
we've seen static routes, group of routes, subdomains, wildcard subdomains, a small example of parameterized path
|
we've seen static routes, group of routes, subdomains, wildcard subdomains, a small example of parameterized path
|
||||||
with a single known paramete and custom http errors, now it's time to see wildcard parameters and macros.
|
with a single known parameter and custom http errors, now it's time to see wildcard parameters and macros.
|
||||||
|
|
||||||
iris, like net/http std package registers route's handlers
|
iris, like net/http std package registers route's handlers
|
||||||
by a Handler, the iris' type of handler is just a func(ctx iris.Context)
|
by a Handler, the iris' type of handler is just a func(ctx iris.Context)
|
||||||
|
@ -876,7 +876,7 @@ Iris has the easiest and the most powerful routing process you have ever meet.
|
||||||
At the same time,
|
At the same time,
|
||||||
iris has its own interpeter(yes like a programming language)
|
iris has its own interpeter(yes like a programming language)
|
||||||
for route's path syntax and their dynamic path parameters parsing and evaluation,
|
for route's path syntax and their dynamic path parameters parsing and evaluation,
|
||||||
I am calling them "macros" for shortcut.
|
We call them "macros" for shortcut.
|
||||||
How? It calculates its needs and if not any special regexp needed then it just
|
How? It calculates its needs and if not any special regexp needed then it just
|
||||||
registers the route with the low-level path syntax,
|
registers the route with the low-level path syntax,
|
||||||
otherwise it pre-compiles the regexp and adds the necessary middleware(s).
|
otherwise it pre-compiles the regexp and adds the necessary middleware(s).
|
||||||
|
@ -895,6 +895,12 @@ Standard macro types for parameters:
|
||||||
int type
|
int type
|
||||||
only numbers (0-9)
|
only numbers (0-9)
|
||||||
|
|
||||||
|
+------------------------+
|
||||||
|
| {param:long} |
|
||||||
|
+------------------------+
|
||||||
|
int64 type
|
||||||
|
only numbers (0-9)
|
||||||
|
|
||||||
+------------------------+
|
+------------------------+
|
||||||
| {param:alphabetical} |
|
| {param:alphabetical} |
|
||||||
+------------------------+
|
+------------------------+
|
||||||
|
@ -917,7 +923,7 @@ Standard macro types for parameters:
|
||||||
+------------------------+
|
+------------------------+
|
||||||
path type
|
path type
|
||||||
anything, should be the last part, more than one path segment,
|
anything, should be the last part, more than one path segment,
|
||||||
i.e: /path1/path2/path3 , ctx.Params().GetString("param") == "/path1/path2/path3"
|
i.e: /path1/path2/path3 , ctx.Params().Get("param") == "/path1/path2/path3"
|
||||||
|
|
||||||
if type is missing then parameter's type is defaulted to string, so
|
if type is missing then parameter's type is defaulted to string, so
|
||||||
{param} == {param:string}.
|
{param} == {param:string}.
|
||||||
|
@ -949,7 +955,7 @@ so don't care about performance here, the only thing it runs at serve time is th
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
Example code:
|
Example Code:
|
||||||
|
|
||||||
|
|
||||||
// you can use the "string" type which is valid for a single path parameter that can be anything.
|
// you can use the "string" type which is valid for a single path parameter that can be anything.
|
||||||
|
@ -1014,18 +1020,9 @@ Example code:
|
||||||
// this is the only macro type that accepts any number of path segments.
|
// this is the only macro type that accepts any number of path segments.
|
||||||
app.Get("/myfiles/{directory:path}", func(ctx iris.Context) {
|
app.Get("/myfiles/{directory:path}", func(ctx iris.Context) {
|
||||||
ctx.Writef("path type accepts any number of path segments, path after /myfiles/ is: %s", ctx.Params().Get("directory"))
|
ctx.Writef("path type accepts any number of path segments, path after /myfiles/ is: %s", ctx.Params().Get("directory"))
|
||||||
})
|
})
|
||||||
|
|
||||||
// for wildcard path (any number of path segments) without validation you can use:
|
app.Run(iris.Addr(":8080"))
|
||||||
// /myfiles/*directory
|
|
||||||
// "{param}"'s performance is exactly the same of ":param"'s.
|
|
||||||
|
|
||||||
// alternatives -> ":param" for single path parameter and "*paramPath" for wildcard path parameter
|
|
||||||
// acquire them by ctx.Params().Get as always.
|
|
||||||
|
|
||||||
if err := app.Run(iris.Addr(":8080")); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1658,13 +1655,18 @@ Examples:
|
||||||
|
|
||||||
https://github.com/kataras/iris/tree/master/_examples
|
https://github.com/kataras/iris/tree/master/_examples
|
||||||
|
|
||||||
Built'n Middleware:
|
Middleware:
|
||||||
|
|
||||||
https://github.com/kataras/iris/tree/master/middleware
|
https://github.com/kataras/iris/tree/master/middleware
|
||||||
|
https://github.com/iris-contrib/middleware
|
||||||
|
|
||||||
Home Page:
|
Home Page:
|
||||||
|
|
||||||
http://github.com/kataras/iris
|
https://iris-go.com
|
||||||
|
|
||||||
|
Book (in-progress):
|
||||||
|
|
||||||
|
https://docs.iris-go.com
|
||||||
|
|
||||||
*/
|
*/
|
||||||
package iris
|
package iris
|
||||||
|
|
Loading…
Reference in New Issue
Block a user