Skip to content

catalystbyzoho/example-go-docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Go Docker App

A web application built with Go that exposes REST API endpoints and provides an interactive web UI to test them.

What the App Does

This application provides:

  1. Three REST API Endpoints:

    • GET /api/health - Health check endpoint that returns the API status and timestamp
    • GET /api/users - Retrieves all users from the system
    • POST /api/users/create - Creates a new user with name and email
  2. 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
  3. 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

Prerequisites

  • Docker installed on your system
  • Docker daemon running

Building the Docker Image

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

Running the Container

To run the container and start the application:

docker run -d -p 9000:9000 --name go-docker-app go-docker-app

This 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-app image

Accessing the Application

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)

Testing the API

Using the Web UI

  1. Navigate to http://localhost:9000 in your browser
  2. Click the "Test Endpoint" button on any of the three endpoint cards
  3. For the "Create User" endpoint, fill in the name and email fields before clicking "Create User"
  4. View the formatted JSON response displayed below each endpoint card

Using cURL

Health Check:

curl http://localhost:9000/api/health

Get All Users:

curl http://localhost:9000/api/users

Create a User:

curl -X POST http://localhost:9000/api/users/create \
  -H "Content-Type: application/json" \
  -d '{"name":"John Doe","email":"john@example.com"}'

Container Management

Stop the container:

docker stop go-docker-app

Start the container:

docker start go-docker-app

View container logs:

docker logs go-docker-app

Remove the container:

docker rm go-docker-app

Remove the image:

docker rmi go-docker-app

Project Structure

go-docker/
├── main.go          # Main application code
├── go.mod           # Go module definition
├── Dockerfile       # Docker build configuration
└── README.md        # This file

Technical Details

  • 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

Notes

  • 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

About

Demo go app deployed on Catalyst Appsail

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published