A simple Go web application that prints environment variables and provides HTTP endpoints.
- Environment Variables Display: Prints all environment variables in a prettified format on startup
- Hello World Endpoint: Simple HTTP endpoint that returns a JSON response
- Environment Variables API: HTTP endpoint that returns all environment variables as JSON
GET /- Hello World endpointGET /env- Returns all environment variables as JSON
- Make sure you have Go installed (version 1.21 or later)
- Navigate to the project directory
- Run the application:
go run main.goThe application will:
- Print all environment variables to the console in a prettified format
- Start an HTTP server on port 8080 (or the port specified in the
PORTenvironment variable)
go run main.gocurl http://localhost:8080/curl http://localhost:8080/envPORT: Specify the port for the HTTP server (defaults to 8080)
To build a binary:
go build -o simple-go-app main.go
./simple-go-appEnvironment variables are printed in a sorted, formatted table with truncated values for readability.
All HTTP endpoints return properly formatted JSON responses with appropriate headers.