packagemainimport("fmt""log""net/http")funchandle()http.HandlerFunc{returnfunc(whttp.ResponseWriter,r*http.Request){panic("i am panic")}}funchandlePanic(nexthttp.HandlerFunc)http.HandlerFunc{returnfunc(whttp.ResponseWriter,r*http.Request){deferfunc(){ifi:=recover();i!=nil{log.Printf("panic at %s: %v",r.URL.Path,i)w.WriteHeader(http.StatusInternalServerError)fmt.Fprint(w,http.StatusText(http.StatusInternalServerError))}}()next(w,r)}}funcmain(){http.ListenAndServe(":8000",handlePanic(handle()))}
···
Love This Content?
Any kind of supports is greatly appreciated! Kindly support me via Bitcoin, Ko-fi, Trakteer, or just continue to read another content. You can write a response via Webmention and let me know the URL via Telegraph.