mirror of
https://github.com/kataras/iris.git
synced 2025-12-18 02:17:05 +00:00
add a way to customize the handler names (recommended: before server execution) so route logging can be more human-friendly on handlers like standard iris middlewares, e.g. request logger
Former-commit-id: 039c233f2d4da0d52b1d6fc86b6d73be14b15608
This commit is contained in:
@@ -2,12 +2,16 @@ package main
|
||||
|
||||
import (
|
||||
"github.com/kataras/iris/v12"
|
||||
"github.com/kataras/iris/v12/middleware/logger"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
app.Logger().SetLevel("debug")
|
||||
|
||||
// Register a request logger middleware to the application.
|
||||
app.Use(logger.New())
|
||||
|
||||
// GET: http://localhost:8080
|
||||
app.Get("/", info)
|
||||
|
||||
@@ -112,6 +116,9 @@ func main() {
|
||||
ctx.Writef(name)
|
||||
})
|
||||
|
||||
app.None("/secret", privateHandler)
|
||||
app.Get("/public", execPrivateHandler)
|
||||
|
||||
// GET: http://localhost:8080/
|
||||
// GET: http://localhost:8080/profile/anyusername
|
||||
// GET: http://localhost:8080/profile/anyusername/backups/any/number/of/paths/here
|
||||
@@ -130,6 +137,15 @@ func main() {
|
||||
app.Listen(":8080")
|
||||
}
|
||||
|
||||
func privateHandler(ctx iris.Context) {
|
||||
ctx.WriteString(`This can only be executed programmatically through server's another route:
|
||||
ctx.Exec(iris.MethodNone, "/secret")`)
|
||||
}
|
||||
|
||||
func execPrivateHandler(ctx iris.Context) {
|
||||
ctx.Exec(iris.MethodNone, "/secret")
|
||||
}
|
||||
|
||||
func info(ctx iris.Context) {
|
||||
method := ctx.Method() // the http method requested a server's resource.
|
||||
subdomain := ctx.Subdomain() // the subdomain, if any.
|
||||
|
||||
Reference in New Issue
Block a user