A Go library providing reusable utilities for building web applications.
go get github.com/harrydayexe/GoWebUtilitiesComposable HTTP middleware following Go's standard net/http pattern. All middleware follow the signature:
type Middleware func(h http.Handler) http.HandlerAvailable middleware:
- Logging - Request logging with structured logging (
log/slog) - MaxBytesReader - Request body size limiting
- SetContentType - Response Content-Type header setting
Example:
package main
import (
"log/slog"
"net/http"
"os"
"github.com/harrydayexe/GoWebUtilities/middleware"
)
func main() {
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`{"status":"ok"}`))
})
stack := middleware.CreateStack(
middleware.NewLoggingMiddleware(logger),
middleware.NewMaxBytesReader(1024*1024), // 1MB limit
middleware.NewSetContentTypeJSON(),
)
http.ListenAndServe(":8080", stack(handler))
}For detailed documentation, use go doc:
# View package documentation
go doc github.com/harrydayexe/GoWebUtilities/middleware
# View specific function documentation
go doc github.com/harrydayexe/GoWebUtilities/middleware.NewLoggingMiddlewareFull documentation is also available on pkg.go.dev.
# Run all tests
go test ./...
# Run with coverage
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.outContributions are welcome! Please ensure all tests pass and code follows Go conventions.