如何实现统一的错误处理逻辑
type appHandler func(writer http.ResponseWriter,
request *http.Request) error

func errWrapper(handler appHandler) func(http.ResponseWriter, *http.Request) {
return func(writer http.ResponseWriter, request *http.Request) {
err := handler(writer, request)
if err != nil {
log.Warn("Error Handling request:%s", err.Error())
code := http.StatusOK
switch {
case os.IsNotExist(err):
code = http.StatusNotFound
case os.IsPermission(err):
code = http.StatusForbidden
default:
code = http.StatusInternalServerError
}
http.Error(writer, http.StatusText(code), code)
}
}
}

更多完整代码后续补充...
错误处理综合示例
★defer + panic + recover

★Type Assertion

★函数式编程的应用