Skip to content

go-middlewares is a collection of commonly used middlewares in Go.

License

Notifications You must be signed in to change notification settings

space-code/go-middlewares

Repository files navigation

go-middlewares

License CI

Description

go-middlewares is a collection of commonly used middlewares in Go.

Usage

  1. The ErrorHandlerMiddleware is a middleware function designed to handle panics and errors that may occur during the execution of an HTTP handler.

Here's an example of how to use it in your code:

// Create a new HTTP handler and wrap it with the ErrorHandlerMiddleware.
handler := ErrorHandlerMiddleware(yourHandler)

// Use the wrapped handler for your server.
http.Handle("/your-route", handler)

// Start your HTTP server.
http.ListenAndServe(":8080", nil)
  1. The LogHandlerMiddleware is designed to log HTTP requests made to your web application. It captures various details about the request and logs them to your preferred output, which is especially useful for debugging and monitoring.
// Create a new HTTP handler and wrap it with the LogHandlerMiddleware.
handler := LogHandlerMiddleware(yourHandler)

// Use the wrapped handler for your HTTP server.
http.Handle("/your-route", handler)

// Start your HTTP server.
http.ListenAndServe(":8080", nil)

Installation

go get github.com/space-code/go-middleware

Communication

  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.

Contributing

Please feel free to help out with this project! If you see something that could be made better or want a new feature, open up an issue or send a Pull Request!

Author

Nikita Vasilev, [email protected]

License

go-middlewares is available under the MIT license. See the LICENSE file for more info.

About

go-middlewares is a collection of commonly used middlewares in Go.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published