func main() {
app := iris.Default()
// This handler will match /user/john but will not match /user/ or /user
app.Get("/user/{name}", func(ctx iris.Context) {
name := ctx.Params().Get("name")
ctx.Writef("Hello %s", name)
})
// However, this one will match /user/john/ and also /user/john/send
// If no other routers match /user/john, it will redirect to /user/john/
app.Get("/user/{name}/{action:path}", func(ctx iris.Context) {
name := ctx.Params().Get("name")
action := ctx.Params().Get("action")
message := name + " is " + action
ctx.WriteString(message)
})
// For each matched request Context will hold the route definition
app.Post("/user/{name:string}/{action:path}", func(ctx iris.Context) {
ctx.GetCurrentRoute().Tmpl().Src == "/user/{name:string}/{action:path}" // true
})
app.Listen(":8080")
}
參數(shù)類型 | Go語言類型 | 驗證 | iris對應檢索 |
string | string | 字符串 | Params().Get |
uuid | string | uuid | Params().Get |
int | int | -9223372036854775808 至 9223372036854775807 | Params().GetInt |
int8 | int8 | -128 至 127 | Params().GetInt8 |
int16 | int16 | -32768 至 32767 | Params().GetInt16 |
int32 | int32 | -2147483648 至 2147483647 | Params().GetInt32 |
int64 | int64 | -9223372036854775808 至 9223372036854775807 | Params().GetInt64 |
unit | uint | 0 至 18446744073709551615 | Params().GetUint |
unit8 | uint8 | 0 至 255 | Params().GetUint8 |
unit16 | uint16 | 0 至 65535 | Params().GetUint16 |
uint32 | uint32 | 0 至 4294967295 | Params().GetUint32 |
uint64 | uint64 | 0 至 18446744073709551615 | Params().GetUint64 |
bool | bool | true 或 false | Params().GetBool |
alphabetical | string | 小寫(大寫)字母 | Params().Get |
file | string | 小寫或大寫字母、數(shù)字、下劃線 (_)、破折號 (-)、點 (.) | Params().Get |
path | string | 可以用斜杠(路徑段)分隔,但應該是路徑路徑的最后一部分 | Params().Get |
更多示例可以點這里找到
更多建議: