mirror of
https://github.com/kataras/iris.git
synced 2025-12-24 05:17:03 +00:00
8.4.0 | New MVC Features | Refactor examples and godoc for go 1.9 use. Read HISTORY.md.
Former-commit-id: 90c05e743052bc3722e7fefaa0cbb0ed5153a1fb
This commit is contained in:
@@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/context"
|
||||
"github.com/kataras/iris/middleware/logger"
|
||||
)
|
||||
|
||||
@@ -28,7 +27,7 @@ func main() {
|
||||
|
||||
app.Use(customLogger)
|
||||
|
||||
h := func(ctx context.Context) {
|
||||
h := func(ctx iris.Context) {
|
||||
ctx.Writef("Hello from %s", ctx.Path())
|
||||
}
|
||||
app.Get("/", h)
|
||||
@@ -40,12 +39,12 @@ func main() {
|
||||
// http errors have their own handlers, therefore
|
||||
// registering a middleare should be done manually.
|
||||
/*
|
||||
app.OnErrorCode(404 ,customLogger, func(ctx context.Context) {
|
||||
app.OnErrorCode(404 ,customLogger, func(ctx iris.Context) {
|
||||
ctx.Writef("My Custom 404 error page ")
|
||||
})
|
||||
*/
|
||||
// or catch all http errors:
|
||||
app.OnAnyErrorCode(customLogger, func(ctx context.Context) {
|
||||
app.OnAnyErrorCode(customLogger, func(ctx iris.Context) {
|
||||
// this should be added to the logs, at the end because of the `logger.Config#MessageContextKey`
|
||||
ctx.Values().Set("logger_message",
|
||||
"a dynamic message passed to the logs")
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/context"
|
||||
"github.com/kataras/iris/middleware/logger"
|
||||
)
|
||||
|
||||
@@ -18,11 +17,11 @@ func main() {
|
||||
defer close()
|
||||
|
||||
app.Use(r)
|
||||
app.OnAnyErrorCode(r, func(ctx context.Context) {
|
||||
app.OnAnyErrorCode(r, func(ctx iris.Context) {
|
||||
ctx.HTML("<h1> Error: Please try <a href ='/'> this </a> instead.</h1>")
|
||||
})
|
||||
|
||||
h := func(ctx context.Context) {
|
||||
h := func(ctx iris.Context) {
|
||||
ctx.Writef("Hello from %s", ctx.Path())
|
||||
}
|
||||
|
||||
@@ -66,7 +65,7 @@ var excludeExtensions = [...]string{
|
||||
".svg",
|
||||
}
|
||||
|
||||
func newRequestLogger() (h context.Handler, close func() error) {
|
||||
func newRequestLogger() (h iris.Handler, close func() error) {
|
||||
close = func() error { return nil }
|
||||
|
||||
c := logger.Config{
|
||||
@@ -93,7 +92,7 @@ func newRequestLogger() (h context.Handler, close func() error) {
|
||||
|
||||
// we don't want to use the logger
|
||||
// to log requests to assets and etc
|
||||
c.AddSkipper(func(ctx context.Context) bool {
|
||||
c.AddSkipper(func(ctx iris.Context) bool {
|
||||
path := ctx.Path()
|
||||
for _, ext := range excludeExtensions {
|
||||
if strings.HasSuffix(path, ext) {
|
||||
|
||||
Reference in New Issue
Block a user