简单实现Go web框架功能。
实现如下功能
- 自定义路由
- 中间件
- 日志
继承BaseController
type HelloController struct {
BaseController
}
方法返回error
func (this *HelloController) Hello() (err error) {
fmt.Println("hello controller, method Hello")
if true {
err = fmt.Errorf("this is error")
return
}
return this.SuccessJson("success")
}
路由注入
r := New()
r.addPath("/hello", Action((*controllers.HelloController).Hello))
简单封装log
日志
go run cmd/main/main.go
make build