func recoverAction() { if err := recover(); err != nil { pc, _, line, _ := runtime.Caller(4) actionName := runtime.FuncForPC(pc).Name() common.LogInfo(actionName + " end") common.LogError(fmt.Sprintf("actionName:%s line:%d, err:%v ", actionName, line, err)) } }
func main() { defer recoverapp() mux := http.NewServeMux() mux.HandleFunc("/", controller.HandlerCore) s := &http.Server{ Addr: fmt.Sprintf(":%d", controller.Configtools.HttpPort), Handler: mux, ReadTimeout: 10 * time.Second, WriteTimeout: 10 * time.Second, MaxHeaderBytes: 1 << 20, } common.LogInfo("web start", controller.Configtools.HttpPort) common.LogError(s.ListenAndServe()) }
func recoverapp() { common.LogInfo("web end") if err := recover(); err != nil { common.LogError("web err:", err) } }