A Go middleware package for standard HTTP request/response handling.
std-middleware/
βββ cmd/
β βββ server/ # Test HTTP server
β βββ main.go
βββ .air.toml # Air hot reload configuration
βββ Makefile # Build and development tasks
βββ go.mod # Go module file
βββ README.md
- Go 1.21 or later
- Air (for hot reloading):
go install github.com/cosmtrek/air@latest
-
Run in development mode with hot reload:
make dev
-
Run the test server:
make run
-
Build the application:
make build
Once the server is running, you can test the endpoints:
- Root endpoint:
curl http://localhost:8080/ - Hello endpoint:
curl http://localhost:8080/hello - Health endpoint:
curl http://localhost:8080/health
make build- Build the applicationmake run- Run the test servermake dev- Run with hot reload (requires Air)make test- Run testsmake clean- Clean build artifactsmake deps- Install and tidy dependenciesmake fmt- Format codemake vet- Vet code
The test server includes example middleware:
- LoggingMiddleware - Logs request details and timing
- CORSMiddleware - Adds CORS headers for cross-origin requests
This project is set up for easy development with:
- Hot reloading via Air
- Comprehensive Makefile for common tasks
- Standard library only (no external dependencies for core functionality)
- Clean project structure suitable for middleware development