A simple Go web server demonstrating basic HTTP routing, middleware, and graceful shutdown using Gorilla Mux and Logrus.
- Install Daytona: Follow the Daytona installation guide.
- Create the Workspace:
daytona create https://github.com/daytonaio/sample-go-web-server.git
- Install Dependencies:
go mod tidy
- Start the Application:
go run main.go
- Simple HTTP server with two routes
- Structured logging with Logrus
- Middleware for request logging
- Panic recovery middleware
- Graceful server shutdown
- Environment variable-based port configuration
main.go: Primary application file with server logicgo.mod: Go module dependency management
- Gorilla Mux: HTTP request routing
- Logrus: Structured logging
- Plain Text Endpoint:
- Set method to
GET - Enter URL:
http://localhost:8080/ - Expected Response:
- Set method to
Hello, World!
- JSON Endpoint:
- Set method to
GET - Enter URL:
http://localhost:8080/json - Expected Response:
- Set method to
{
"message": "Hello, JSON World!"
}GET /: Returns a plain text "Hello, World!" messageGET /json: Returns a JSON response
Configure the server port using the PORT environment variable. Defaults to 8080 if not specified.