We want to collect feedback from Users in a more privacy-friendly way, without collecting additional data or denying to do for 3rd parties.
Simple HTTPS API backend service, which will get data in JSON format and send it to an internal email (v1) to read.
This section describe how to directly compile and run the application assuming the Go programming language compiler is installed.
Alternatively the use of Docker Composer is described in the next section.
The application can be build as follows:
go build
The application directly compiled with Go can be started as follows:
./feedback-api \
-from "no-reply@example.com" \
-to foo@barbaz.com \
-smtp-server smtp.abc.xyz \
-smtp-port 465 \
-http-port 8001
As a result, an HTTP server should be listenning on localhost:8001
(CTRL+C to stop).
There are a few environment variables avaialble to configure the application:
false
to disable TLS, which can be useful if you want to use a dummy SMTP server for local development.true
to allow insecure TLS, which can be useful if you want to test with a self-sign certificate server in development env.Example:
SMTP_HELO="gw.example.com" \
SMTP_USERNAME="foo@foobar.in" \
SMTP_PASSWORD="barbazquux" \
SMTP_USE_INSECURE_TLS=true \
./feedback-api \
-from "no-reply@example.com" \
-to foo@barbaz.com \
-smtp-server localhost
IMPORTANT: If you are using bash
, before typing in the command above, type a SPC
character, so that the above command carrying the username and password won't get into the bash history.
Once the application in running, a POST request can be sent:
curl \
--request POST \
--header "Content-Type: application/json" \
--data '{"feedback":{"title": "Full Feedback Form","rate": {"type" : "numbers","value" : 10},"questions":[{"question":"q1","answer":"a1"},{"question":"q2","answer":"a2"}]}}' \
http://localhost:8001/v1/feedback
REM: The JSON content needs to match the defined template!
To facilitate integration and testing, Docker Composer support is provided in this repo.
This also include a dummy SMTP server for testing purpose.
This method relies exclusively on environment variables which means both the application parameters and the above described variables need to be defined in a local .env
file (ignored by Git):
SMTP_FROM=no-reply@example.com
SMTP_TO=foo@barbaz.com
SMTP_SERVER=smtp.abc.xyz
SMTP_PORT=465
HTTP_PORT=8001
SMTP_HELO=http-server1.local
SMTP_USERNAME=foo@foobar.in
SMTP_PASSWORD=barbazquux
SMTP_USE_TLS=true
SMTP_USE_INSECURE_TLS=true
It is recommended to explicitly build the images at least once, then subsequently in case of changes on Docker config and/or images:
docker-compose [--compatibility] build
The following command should start the required services:
docker-compose [--compatibility] up
REM: Use the --compatibility
switch (if supported) whenever resources need to be limitted (CPU and MEM).
From this point, the service(s) (http and smtp) should be running and ready to be tested (see curl
command above).
If needed, Docker compose can also be used to start a single service.
For instance, here is how to run a standalone HTTP server w/o the SMTP service:
docker-compose [--compatibility] run \
--no-deps \
--rm \
--publish 8001:8001 \
-e SMTP_SERVER=smtp.example.com \
-e SMTP_PORT=465 \
-e SMTP_USE_TLS=true \
http-server1