mirror of
https://github.com/kataras/iris.git
synced 2025-12-21 11:57:02 +00:00
New ':int64' and ':uint64' route path parameters - and - support the new uint64 for MVC (int64 was already supported there) - and - add ctx.Params().GetUint64 (GetInt64 was already there) - and - make the ':int or :number' to accept negative numbers with no digit limit (at low level) and rename the 'app.Macros().Int.RegisterFunc' to 'Number.RegisterFunc' because number can be any type of number not only standard go type limited - and - add alias for ':boolean' -> ':bool'. Finally, Update the examples but not the version yet, I have to provide a good README table to explain the end-developers how they can benefit by those changes and why the breaking change (which is to accept negative numbers via ':int') is for their own good and how they can make their own macro functions so they do not depend on the Iris builtn macro funcs only. More to come tomorrow, stay tuned
Former-commit-id: 3601abfc89478185afec3594375080778214283e
This commit is contained in:
@@ -29,12 +29,12 @@ func main() {
|
||||
app.Get("/donate", donateHandler, donateFinishHandler)
|
||||
|
||||
// Pssst, don't forget dynamic-path example for more "magic"!
|
||||
app.Get("/api/users/{userid:int min(1)}", func(ctx iris.Context) {
|
||||
userID, err := ctx.Params().GetInt("userid")
|
||||
app.Get("/api/users/{userid:uint64 min(1)}", func(ctx iris.Context) {
|
||||
userID, err := ctx.Params().GetUint64("userid")
|
||||
|
||||
if err != nil {
|
||||
ctx.Writef("error while trying to parse userid parameter," +
|
||||
"this will never happen if :int is being used because if it's not integer it will fire Not Found automatically.")
|
||||
"this will never happen if :uint64 is being used because if it's not a valid uint64 it will fire Not Found automatically.")
|
||||
ctx.StatusCode(iris.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
@@ -103,7 +103,7 @@ func main() {
|
||||
ctx.Writef("All users")
|
||||
})
|
||||
// http://v1.localhost:8080/api/users/42
|
||||
usersAPI.Get("/{userid:int}", func(ctx iris.Context) {
|
||||
usersAPI.Get("/{userid:number}", func(ctx iris.Context) {
|
||||
ctx.Writef("user with id: %s", ctx.Params().Get("userid"))
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user