1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-10 21:45:57 +00:00

fix 2 minor issues

This commit is contained in:
Gerasimos (Makis) Maropoulos
2022-02-26 21:16:08 +02:00
parent 09f494e406
commit 20fa672097
7 changed files with 49 additions and 19 deletions

View File

@@ -47,19 +47,20 @@ func newApp() *iris.Application {
// or 202 status code and empty body
// or a 409 status code and "my_error" body.
app.ConfigureContainer(func(api *iris.APIContainer) {
// TODO: fix that test as well.
// api.Self.SetExecutionRules(iris.ExecutionRules{
// Begin: iris.ExecutionOptions{
// Force: true,
// },
// })
// Enable execution of middlewares without ctx.Next requirement.
api.Self.SetExecutionRules(iris.ExecutionRules{
Begin: iris.ExecutionOptions{
Force: true,
},
})
api.Use(middleware)
api.Post("/{id:int}", handler)
})
app.Configure(
iris.WithOptimizations, /* optional */
iris.WithoutBodyConsumptionOnUnmarshal /* required when more than one handler is consuming request payload(testInput) */)
iris.WithOptimizations, /* optional */
iris.WithoutBodyConsumptionOnUnmarshal, /* required when more than one handler is consuming request payload(testInput) */
)
return app
}

View File

@@ -58,7 +58,7 @@ func postIndexStream(ctx iris.Context) {
var users []User
job := func(decode iris.DecodeFunc) error {
var u User
if err := decode(&u); err != nil {
if err := decode(ctx, &u); err != nil {
return err
}
users = append(users, u)

View File

@@ -40,10 +40,7 @@ func newApp(db *DB) *iris.Application {
//
// Look ./templates/index.html#L16
tmpl.AddFunc("IsPositive", func(n int) bool {
if n > 0 {
return true
}
return false
return n > 0
})
app.RegisterView(tmpl)
@@ -72,7 +69,7 @@ func newApp(db *DB) *iris.Application {
return
}
ctx.Redirect(value, iris.StatusTemporaryRedirect)
ctx.Redirect(value, iris.StatusBadGateway)
}
app.Get("/u/{shortkey}", func(ctx iris.Context) {
execShortURL(ctx, ctx.Params().Get("shortkey"))

View File

@@ -37,7 +37,7 @@ func TestURLShortener(t *testing.T) {
// get
e.GET("/u/" + keys[0]).Expect().
Status(httptest.StatusTemporaryRedirect).Header("Location").Equal(originalURL)
Status(httptest.StatusBadGateway).Header("Location").Equal(originalURL)
// save the same again, it should add a new key
e.POST("/shorten").