Configuration
GoApp is configured using environment variables. This approach is aligned with Twelve-Factor App principles, making the application portable and easy to manage across different environments (local, staging, production).
All configuration loading is handled in the internal/configs package.
General Application Settings
| Environment Variable | Description | Default |
|---|---|---|
ENV |
Sets the application environment. Affects things like access logging. Options: local, test, staging, production. |
local |
APP_NAME |
The name of the application, used in logging and observability (APM). | "" |
APP_VERSION |
The version of the application, used in logging and observability (APM). | "" |
HTTP Server Configuration
| Environment Variable | Description | Default Value from Code |
|---|---|---|
TEMPLATES_BASEPATH |
The absolute file path to the directory containing HTML templates. | "" |
Note: While host and port are configurable in the http.Config struct, they are currently hardcoded in configs.go to port 8080.
PostgreSQL Database Configuration
These variables are essential for connecting to the PostgreSQL database.
| Environment Variable | Description | Example |
|---|---|---|
POSTGRES_HOST |
The hostname of the database server. | localhost or postgres (in Docker) |
POSTGRES_PORT |
The port the database is running on. | 5432 |
POSTGRES_STORENAME |
The name of the database to connect to. | goapp |
POSTGRES_USERNAME |
The username for authentication. | gauser |
POSTGRES_PASSWORD |
The password for authentication. | gauserpassword |
Example Configuration (.env file)
For local development, you can create a file named .env and use a tool like source to load the variables into your shell.
# Application Environment
export ENV=local
export APP_NAME=goapp
export APP_VERSION=v1.0.0
# Database Configuration
export POSTGRES_HOST=localhost
export POSTGRES_PORT=5432
export POSTGRES_STORENAME=goapp
export POSTGRES_USERNAME=gauser
export POSTGRES_PASSWORD=gauserpassword
# HTTP Server Configuration
# Use ${PWD} to ensure the path is absolute from your project root
export TEMPLATES_BASEPATH=${PWD}/cmd/server/http/web/templates