feat: add Go microservice, Dockerfile, docker-compose, and API submission endpoint

This commit is contained in:
2026-08-12 17:20:03 +02:00
parent ad02939b88
commit 0ee82eb673
24 changed files with 316 additions and 6 deletions
@@ -0,0 +1,20 @@
I want to add backend functionality to send the survey responses as an email upon submission using Option 1 (a minimalist Go/Golang microservice).
Please complete the following tasks:
1. Go Microservice (`main.go`):
- Create a lightweight HTTP server using standard Go library packages (`net/http`, `net/smtp`, `encoding/json`).
- Create an endpoint (e.g., `POST /api/submit`) to accept JSON payload survey data from the front end.
- Configure SMTP credentials and server settings via environment variables (e.g., `SMTP_HOST`, `SMTP_PORT`, `SMTP_USER`, `SMTP_PASS`, `TO_EMAIL`) via an .env file
- Format the incoming JSON survey data into a clean, readable text body and dispatch the email upon request.
- Handle CORS preflight (`OPTIONS`) and headers so the HTML/JS front end can POST to it smoothly.
2. Dockerization (`Dockerfile`):
- Provide a multi-stage `Dockerfile` (e.g., compile with `golang:alpine`, copy to `scratch` or `alpine`) to ensure the resulting container image is ultra-lightweight (<20MB).
3. Front-End Integration:
- Show how to update the existing JavaScript submission handler (using `fetch()`) to send the survey data as JSON to the new Go backend endpoint.
Please keep the code minimalist, robust, and well-commented.
when everything works, please create a simple docker-compose file that builds the project and runs the container. include traefik labels for reverse proxy routing.