mirror of
https://github.com/kataras/iris.git
synced 2026-03-06 08:25:59 +00:00
fix https://github.com/kataras/iris/issues/1713 and add a simple usage example of the 'RemoveHandler'
This commit is contained in:
@@ -48,6 +48,7 @@
|
||||
* Middleware
|
||||
* [Per Route](routing/writing-a-middleware/per-route/main.go)
|
||||
* [Globally](routing/writing-a-middleware/globally/main.go)
|
||||
* [Remove a Handler](routing/remove-handler/main.go)
|
||||
* Share Values
|
||||
* [Share Services](routing/writing-a-middleware/share-services/main.go)
|
||||
* [Share Functions](routing/writing-a-middleware/share-funcs/main.go)
|
||||
|
||||
29
_examples/routing/remove-handler/main.go
Normal file
29
_examples/routing/remove-handler/main.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package main
|
||||
|
||||
import "github.com/kataras/iris/v12"
|
||||
|
||||
func main() {
|
||||
app := newApp()
|
||||
app.Listen(":8080")
|
||||
}
|
||||
|
||||
func newApp() *iris.Application {
|
||||
app := iris.New()
|
||||
|
||||
api := app.Party("/api")
|
||||
api.Use(myMiddleware)
|
||||
users := api.Party("/users")
|
||||
users.Get("/", usersIndex).RemoveHandler(myMiddleware)
|
||||
// OR for all routes under a Party (or Application):
|
||||
// users.RemoveHandler(...)
|
||||
|
||||
return app
|
||||
}
|
||||
|
||||
func myMiddleware(ctx iris.Context) {
|
||||
ctx.WriteString("Middleware\n")
|
||||
}
|
||||
|
||||
func usersIndex(ctx iris.Context) {
|
||||
ctx.WriteString("OK")
|
||||
}
|
||||
14
_examples/routing/remove-handler/main_test.go
Normal file
14
_examples/routing/remove-handler/main_test.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/kataras/iris/v12/httptest"
|
||||
)
|
||||
|
||||
func TestSimpleRouteRemoveHandler(t *testing.T) {
|
||||
app := newApp()
|
||||
e := httptest.New(t, app)
|
||||
|
||||
e.GET("/api/users").Expect().Status(httptest.StatusOK).Body().Equal("OK")
|
||||
}
|
||||
Reference in New Issue
Block a user