Configuration (core/config)
Configuration is loaded by github.com/mmycin/goforge/core/config using spf13/viper:
setDefaults()registers code defaults.- Reads
.env(SetConfigFile(".env"),SetConfigType("env")). If.envis missing, logs a warning and continues with OS environment variables and defaults; parse errors fail immediately. - Enables
viper.AutomaticEnv()so OS environment variables always override.env. - Returns
*config.AllConfig(preferred for DI injection) and populates legacy package-level globals (config.App,config.DB,config.GRPC,config.HTTP,config.Encrypt,config.Log).
Complete Environment Variable Reference
Application (AppConfig / cfg.App)
| Field | Go Type | Env Var | Code Default | .env.example |
|---|---|---|---|---|
Name | string | APP_NAME | "" | goforge |
Version | string | APP_VERSION | "" | 1.0.0 |
Module | string | APP_MODULE | "" | github.com/mmycin/goforge |
Debug | bool | APP_DEBUG | false | true |
Key | string | APP_KEY | "" | (generate via goforge gen:key) |
Host | string | APP_HOST | "127.0.0.1" | 127.0.0.1 |
Port | int | APP_PORT | 3000 | 3000 |
HTTP Server (HTTPConfig / cfg.HTTP)
| Field | Go Type | Env Var | Code Default | .env.example |
|---|---|---|---|---|
RateLimitPerMinute | int | RATE_LIMIT_PER_MINUTE | 0 (disabled) | 10 |
CORSAllowedOrigins | string | CORS_ALLOWED_ORIGINS | "" (treats as *) | # * |
TrustedProxies | string | TRUSTED_PROXIES | "" (trusts none) | # (empty) |
ReadHeaderTimeout | time.Duration | HTTP_READ_HEADER_TIMEOUT | 10s | # 10s |
ReadTimeout | time.Duration | HTTP_READ_TIMEOUT | 30s | # 30s |
WriteTimeout | time.Duration | HTTP_WRITE_TIMEOUT | 30s | # 30s |
IdleTimeout | time.Duration | HTTP_IDLE_TIMEOUT | 120s | # 120s |
TLSEnabled | bool | TLS_ENABLED | false | false |
TLSCertFile | string | TLS_CERT_FILE | "" | cert.pem |
TLSKeyFile | string | TLS_KEY_FILE | "" | key.pem |
gRPC Server (GRPCConfig / cfg.GRPC)
| Field | Go Type | Env Var | Code Default | .env.example |
|---|---|---|---|---|
Enable | bool | GRPC_ENABLE | false | true |
Reflection | bool | GRPC_REFLECTION | false | true |
Host | string | GRPC_HOST | "127.0.0.1" | 127.0.0.1 |
Port | int | GRPC_PORT | 50051 | 50051 |
TLSEnabled | bool | GRPC_TLS_ENABLED | false | # false |
TLSCertFile | string | GRPC_TLS_CERT_FILE | "" | # cert.pem |
TLSKeyFile | string | GRPC_TLS_KEY_FILE | "" | # key.pem |
Database (DBConfig / cfg.DB)
| Field | Go Type | Env Var | Code Default | .env.example |
|---|---|---|---|---|
Connection | string | DB_CONNECTION | "" | sqlite |
Name | string | DB_NAME | "" | forge.db |
DevName | string | DB_DEV_NAME | "" | # forge_dev |
Host | string | DB_HOST | "" | 127.0.0.1 |
Port | int | DB_PORT | 0 | 3306 |
Username | string | DB_USERNAME | "" | root |
Password | string | DB_PASSWORD | "" | root |
Migrator | string | DB_MIGRATOR | "" (migrate defaults to atlas) | atlas |
SSLMode | string | DB_SSL_MODE | "disable" | # disable |
MaxOpenConns | int | DB_MAX_OPEN_CONNS | 25 | # 25 |
MaxIdleConns | int | DB_MAX_IDLE_CONNS | 5 | # 5 |
ConnMaxLifetime | time.Duration | DB_CONN_MAX_LIFETIME | 5m | # 5m |
Encryption (EncryptConfig / cfg.Encrypt)
| Field | Go Type | Env Var | Code Default | .env.example |
|---|---|---|---|---|
Key | string | ENCRYPTION_KEY | "" | (empty) |
Rounds | int | ENCRYPTION_ROUNDS | 0 | 12 |
Salt | string | ENCRYPTION_SALT | "" | (empty) |
Logging (LogConfig / cfg.Log)
| Field | Go Type | Env Var | Code Default | .env.example |
|---|---|---|---|---|
Type | string | LOG_TYPE | "" (treats as terminal) | terminal (terminal | file | both) |
Level | string | LOG_LEVEL | "info" | info |
Path | string | LOG_PATH | "" | storage/logs/app.log |
Format | string | LOG_FORMAT | "" (treats as log) | log (json | yaml | log) |
Color | string | LOG_COLOR | "" (treats as auto) | auto (auto | always | never) |
core/console also honors standard terminal environment variables: NO_COLOR, FORCE_COLOR, TERM, and CI.
Validation (Validate vs ValidateForServe)
(*AllConfig).Validate() error(called on every CLI command viaPersistentPreRunE):- Verifies
APP_PORTandGRPC_PORTare in[0, 65535]. - Requires non-blank
TLS_CERT_FILE&TLS_KEY_FILEwhenTLS_ENABLED=true. - Requires non-blank
GRPC_TLS_CERT_FILE&GRPC_TLS_KEY_FILEwhenGRPC_TLS_ENABLED=true. - Requires
DB_CONNECTION(when non-empty) to be one ofsqlite,postgres,mysql,sqlserver.
- Verifies
(*AllConfig).ValidateForServe() error(called byserve):- Runs
Validate(), then rejects an empty or whitespace-onlyAPP_KEY.
- Runs
Adding Custom Configuration
Run goforge gen:config <name> to scaffold core/config/<name>.go and wire it into AllConfig and Load() (see CLI gen:config for the manual var (...) line check).
