-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
main.go
39 lines (30 loc) · 820 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"fmt"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/mvc"
)
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
app.Listen(":8080")
}
type myController struct {
}
// overriddes the mvcApp.HandleError function.
func (c *myController) HandleError(ctx iris.Context, err error) {
ctx.HTML(fmt.Sprintf("<i>%s</i>", err.Error()))
}
func (c *myController) Get() error {
return fmt.Errorf("error here")
}