槽痞

golang 在http中的异常处理

func logPanics(handle http.HandlerFunc) http.HandlerFunc{
    return  func(write http.ResponseWriter,request *http.Request){
        defer func(){
            if x := recover(); x!=nil{
                log.Printf("[%v] caught panic:%v",request.RemoteAddr,x)
            }
        }()
        handle(write, request)
    }

}

当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »