Configuration

The application is configured using environment variables. A file named .env in the project root will be automatically loaded on startup.

An example configuration file, example.env, is provided in the repository. To get started, you can copy this file to .env:

cp example.env .env

The default values are suitable for the local Docker-based development environment.

Environment Variables

Below is a list of all the environment variables used by the application.

Variable Description Default Value Example
DEBUG A flag to enable debug mode (currently not used). True False
SERVER_ADDRESS The address and port for the HTTP server to listen on. :9090 :8080
CONTEXT_TIMEOUT The timeout in seconds for each incoming HTTP request. 2 5
DATABASE_HOST The hostname or IP address of the MySQL database. localhost mysql (in Docker network)
DATABASE_PORT The port number of the MySQL database. 3306 3306
DATABASE_USER The username for connecting to the MySQL database. user myuser
DATABASE_PASS The password for the specified database user. password secret
DATABASE_NAME The name of the database to use. article prod_db

Server Configuration

  • SERVER_ADDRESS: Specifies the network interface and port the Echo web server will bind to. The default :9090 listens on port 9090 on all available network interfaces.
  • CONTEXT_TIMEOUT: This is a crucial setting for service reliability. It creates a context.WithTimeout for each request, ensuring that no request can hang indefinitely. If a request handler (including database queries) takes longer than this duration, the context will be canceled, and an error will be returned to the client.

Database Configuration

These variables are used to construct the Data Source Name (DSN) for the MySQL connection.

  • When running with docker-compose up, the application code runs on your host machine, so DATABASE_HOST should be localhost or 127.0.0.1 to connect to the MySQL container whose port 3306 is exposed to the host.
  • If you were running the application inside the Docker network (e.g., via docker-compose up web), DATABASE_HOST would need to be mysql, which is the service name defined in compose.yaml.