mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 10:41:03 +01:00
30 lines
530 B
Go
30 lines
530 B
Go
|
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")
|
||
|
}
|