Shop configuration options

Name Type Env Values Default Description
Env string ENV prod, dev, test prod Server mode
RootDir string ROOT_DIR Root dir
TmpDir string TMP_DIR tmp Temporary files dir
NoLog bool NO_LOG true false Disable std log output

Example

[shop]
RootDir="/app"
TmpDir="/tmp"

Database

We currently support sqlite3, postgres and cockroach databases.

Name Type Env Values Default Description
Type string DB_TYPE postgres,sqlite3 Database type
Dsn string DB_CONNECTION Database url
Host string DB_HOST Database host
Port uint DB_PORT 1-65535 Database port
Name string DB_NAME Database name
User string DB_USER Database user
Pass string DB_PASS database password
ConnMaxLifetime time duration DB_CONN_MAX_LIFETIME “100s”,“10m” Connection life time
MaxIdleConns int DB_MAX_IDLE_CONNS Max idle connections
MaxOpenConns int DB_MAX_OPEN_CONNS Max open connections
ReadOnly bool DB_READ_ONLY false Read only mode
Migrate bool DB_MIGRATE false Enable migrations

If you use dsn you don’t need to specify database type, host, port, name, user or pass.

Migrations

Upon startup the system checks if there are any pending database schema migrations and applies them in sequence. If one of the migrations fail everything gets rolled back and the startup fails with details in its log output.

The Migrate setting allows you to control automatic schema migrations. If you want to update or upgrade the system you cannot have ReadOnly mode and must set Migrate to true.

Database opts

The opts setting allows you to set additional configuration parameters for the database.

Name Type Env Values Default Description
Set string Option setting
Val string Option value

The options you can set depends on the database type and version you are using.

Example sqlite3 database configuration.

[shop.database]
type = "sqlite3"
name = "/storage/shop.db"
migrate = true
[[shop.database.opts]]
set = "foreign_keys"
val = "ON"
[[shop.database.opts]]
set = "journal_mode"
val = "WAL"

The database gets created if it doesn’t exist.

Example Postgres database configuration.

[shop.database]
type = "postgres"
name = "shop"
user = "postgres"
pass = "postgres"
host = "127.0.0.1"
port = 5432
migrate = true

If you have granted create database permission to the db user the database is created.

Example Cockroach database configuration using dsn.

[shop.database]
dsn = "cockroach://root@localhost:26257/shop?sslmode=disable"
migrate = true

You must first create the shop database in cockroach or it will use defaultdb instead.

Backend

Server backend url (message bus).

Name Type Env Values Default Description
Url string BACKEND_URL url Url to backend server (message bus)

Example

[shop.backend]
url = "nats://172.16.172.16:4222"