A web application built with Go that exposes REST API endpoints and provides an interactive web UI to test them.
This application provides:
-
Three REST API Endpoints:
GET /api/health- Health check endpoint that returns the API status and timestampGET /api/users- Retrieves all users from the systemPOST /api/users/create- Creates a new user with name and email
-
Interactive Web UI:
- Responsive HTML interface accessible at the root endpoint (
/) - Mobile and desktop friendly design
- Allows users to test all three API endpoints directly from the browser
- Displays formatted JSON responses
- Responsive HTML interface accessible at the root endpoint (
-
In-Memory User Storage:
- The application maintains an in-memory list of users
- Sample users are initialized on startup
- New users can be created via the POST endpoint
- Docker installed on your system
- Docker daemon running
To build the Docker image for the linux/amd64 platform, run:
docker build --platform=linux/amd64 -t go-docker-app .This command will:
- Build a multi-stage Docker image
- Compile the Go application for linux/amd64 platform
- Create a minimal Alpine-based final image
- Tag the image as
go-docker-app
To run the container and start the application:
docker run -d -p 9000:9000 --name go-docker-app go-docker-appThis command will:
- Run the container in detached mode (
-d) - Map port 9000 from the container to port 9000 on your host (
-p 9000:9000) - Name the container
go-docker-app(--name go-docker-app) - Use the
go-docker-appimage
Once the container is running, you can access the application:
- Web UI: Open your browser and navigate to
http://localhost:9000 - API Endpoints:
- Health Check:
http://localhost:9000/api/health - Get Users:
http://localhost:9000/api/users - Create User:
http://localhost:9000/api/users/create(POST request)
- Health Check:
- Navigate to
http://localhost:9000in your browser - Click the "Test Endpoint" button on any of the three endpoint cards
- For the "Create User" endpoint, fill in the name and email fields before clicking "Create User"
- View the formatted JSON response displayed below each endpoint card
Health Check:
curl http://localhost:9000/api/healthGet All Users:
curl http://localhost:9000/api/usersCreate a User:
curl -X POST http://localhost:9000/api/users/create \
-H "Content-Type: application/json" \
-d '{"name":"John Doe","email":"john@example.com"}'Stop the container:
docker stop go-docker-appStart the container:
docker start go-docker-appView container logs:
docker logs go-docker-appRemove the container:
docker rm go-docker-appRemove the image:
docker rmi go-docker-appgo-docker/
├── main.go # Main application code
├── go.mod # Go module definition
├── Dockerfile # Docker build configuration
└── README.md # This file
- Language: Go 1.21
- Port: 9000
- Base Image: Alpine Linux (minimal footprint)
- Build Platform: linux/amd64
- Architecture: Multi-stage Docker build for optimized image size
- User data is stored in-memory and will be lost when the container stops
- The application initializes with two sample users on startup
- All API endpoints return JSON responses
- CORS is not configured, so API calls from external domains may be restricted