7days-golang icon indicating copy to clipboard operation
7days-golang copied to clipboard

middlewares: remove the deformed anonymous function and the stupid in…

Open chensanle opened this issue 1 year ago • 0 comments

r.Use(gee.Logger())
func Logger() HandlerFunc {
    return func(c *Context) {
        // ...        
    }
}

r.Use(gee.Logger)
func Logger(c *Context) {
    // ...
}

我理解 go 的隐式接口实现在阅读上会有一定的障碍,显示返还接口的形式使得可读性在某些方面得到一定的缓解,但是无用的匿名函数和冗余的缩进严重的提高了程序复杂性。 您这边的教学对 golang 入门用户有深远的影响,但您知道一个中间件内,内嵌了一个三千行的匿名函数有多么的可怕么?

chensanle avatar Sep 08 '22 15:09 chensanle