2019-04-16 17:01:48 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2019-10-25 00:27:02 +02:00
|
|
|
"github.com/kataras/iris/v12"
|
2019-04-16 17:01:48 +02:00
|
|
|
|
2019-10-25 00:27:02 +02:00
|
|
|
"github.com/kataras/iris/v12/mvc"
|
2019-04-16 17:01:48 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
app := iris.New()
|
|
|
|
app.Logger().SetLevel("debug")
|
|
|
|
|
|
|
|
mvcApp := mvc.New(app)
|
|
|
|
// To all controllers, it can optionally be overridden per-controller
|
|
|
|
// if the controller contains the `HandleError(ctx iris.Context, err error)` function.
|
|
|
|
//
|
|
|
|
mvcApp.HandleError(func(ctx iris.Context, err error) {
|
|
|
|
ctx.HTML(fmt.Sprintf("<b>%s</b>", err.Error()))
|
|
|
|
})
|
|
|
|
//
|
|
|
|
mvcApp.Handle(new(myController))
|
|
|
|
|
|
|
|
// http://localhost:8080
|
2020-03-05 21:41:27 +01:00
|
|
|
app.Listen(":8080")
|
2019-04-16 17:01:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type myController struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
// overriddes the mvcApp.HandleError function.
|
2019-04-16 17:08:03 +02:00
|
|
|
func (c *myController) HandleError(ctx iris.Context, err error) {
|
|
|
|
ctx.HTML(fmt.Sprintf("<i>%s</i>", err.Error()))
|
|
|
|
}
|
2019-04-16 17:01:48 +02:00
|
|
|
|
|
|
|
func (c *myController) Get() error {
|
|
|
|
return fmt.Errorf("error here")
|
|
|
|
}
|