1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-17 18:07:01 +00:00

add a new 'uuid' path parameter type e.g. /{id:uuid}

This commit is contained in:
Gerasimos (Makis) Maropoulos
2021-02-12 17:12:23 +02:00
parent 590e999688
commit 5fe233278a
4 changed files with 58 additions and 0 deletions

View File

@@ -147,6 +147,17 @@ func main() {
// app.Macros().String.RegisterFunc("equal", func(argument string) func(paramValue string) bool {
// return func(paramValue string) bool { return argument == paramValue }
// })
// +------------------------+
// | {param:uuid} |
// +------------------------+
// UUIDv4 (and v1) path parameter validation.
// http://localhost:8080/user/bb4f33e4-dc08-40d8-9f2b-e8b2bb615c0e -> OK
// http://localhost:8080/user/dsadsa-invalid-uuid -> NOT FOUND
app.Get("/user/{id:uuid}", func(ctx iris.Context) {
id := ctx.Params().Get("id")
ctx.WriteString(id)
})
// you can use the "string" type which is valid for a single path parameter that can be anything.
app.Get("/username/{name}", func(ctx iris.Context) {