1.4 KiB
1.4 KiB
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:
-
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.
- Create a lightweight HTTP server using standard Go library packages (
-
Dockerization (
Dockerfile):- Provide a multi-stage
Dockerfile(e.g., compile withgolang:alpine, copy toscratchoralpine) to ensure the resulting container image is ultra-lightweight (<20MB).
- Provide a multi-stage
-
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.
- Show how to update the existing JavaScript submission handler (using
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.