https://github.com/space-code/go-middlewares
go-middlewares is a collection of commonly used middlewares in Go.
https://github.com/space-code/go-middlewares
go golang middleware middlewares
Last synced: 7 months ago
JSON representation
go-middlewares is a collection of commonly used middlewares in Go.
- Host: GitHub
- URL: https://github.com/space-code/go-middlewares
- Owner: space-code
- License: mit
- Created: 2023-10-30T13:45:48.000Z (over 2 years ago)
- Default Branch: dev
- Last Pushed: 2023-11-13T17:37:21.000Z (over 2 years ago)
- Last Synced: 2025-02-28T18:25:21.621Z (about 1 year ago)
- Topics: go, golang, middleware, middlewares
- Language: Go
- Homepage:
- Size: 13.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
go-middlewares
## Description
`go-middlewares` is a collection of commonly used middlewares in Go.
- [Usage](#usage)
- [Installation](#installation)
- [Communication](#communication)
- [Contributing](#contributing)
- [Author](#author)
- [License](#license)
## 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:
```go
// 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)
```
2. 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.
```go
// 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, nv3212@gmail.com
## License
go-middlewares is available under the MIT license. See the LICENSE file for more info.