Release Notes: go-panic-proof v1.0.0 🎉
We are excited to announce the release of go-panic-proof, a robust middleware package for recovering from panics in both HTTP and gRPC servers. This release ensures your server stays resilient under unexpected conditions, providing detailed error logs and appropriate responses to clients.
Key Features 🚀
- HTTP Middleware: Seamlessly recover from panics in HTTP handlers and respond with a
500 Internal Server Error
. - gRPC Interceptor: Safeguard gRPC methods by recovering from panics and logging comprehensive error details.
- Detailed Logging: Capture and log the panic message with a full stack trace for easier debugging.
- Customizable Error Handling: Use
HTTPRecoverWithHandler
to provide tailored error responses or perform additional recovery actions.
Installation 📦
go get github.com/srahkmli/go-panic-proof
Example Usage 🌟
HTTP Recovery:
http.Handle("/example", HTTPRecover(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
panic("example panic")
})))
gRPC Recovery:
grpcServer := grpc.NewServer(
grpc.UnaryInterceptor(RecoverInterceptor),
)
Custom HTTP Error Handling:
customHandler := func(w http.ResponseWriter, r *http.Request, err interface{}) {
log.Printf("Custom error handler: %v", err)
http.Error(w, "Something went wrong", http.StatusInternalServerError)
}
http.Handle("/custom", HTTPRecoverWithHandler(http.Handler