feat(01-01): create configuration infrastructure
- AppConfig, ServerConfig, DatabaseConfig case classes - zio-config-magnolia for automatic Config derivation - HOCON application.conf with env variable overrides - Server: host/port with SERVER_HOST/SERVER_PORT overrides - Database: host/port/database/user/password with DB_* overrides
This commit is contained in:
19
summercms/resources/application.conf
Normal file
19
summercms/resources/application.conf
Normal file
@@ -0,0 +1,19 @@
|
||||
server {
|
||||
host = "0.0.0.0"
|
||||
host = ${?SERVER_HOST}
|
||||
port = 8080
|
||||
port = ${?SERVER_PORT}
|
||||
}
|
||||
|
||||
database {
|
||||
host = "localhost"
|
||||
host = ${?DB_HOST}
|
||||
port = 5432
|
||||
port = ${?DB_PORT}
|
||||
database = "summercms"
|
||||
database = ${?DB_NAME}
|
||||
user = "summercms"
|
||||
user = ${?DB_USER}
|
||||
password = "summercms"
|
||||
password = ${?DB_PASSWORD}
|
||||
}
|
||||
64
summercms/src/config/AppConfig.scala
Normal file
64
summercms/src/config/AppConfig.scala
Normal file
@@ -0,0 +1,64 @@
|
||||
package config
|
||||
|
||||
import zio.Config
|
||||
import zio.config.magnolia.deriveConfig
|
||||
|
||||
/** Server configuration
|
||||
*
|
||||
* @param host
|
||||
* Server bind host
|
||||
* @param port
|
||||
* Server bind port
|
||||
*/
|
||||
final case class ServerConfig(
|
||||
host: String,
|
||||
port: Int
|
||||
)
|
||||
|
||||
object ServerConfig {
|
||||
given config: Config[ServerConfig] = deriveConfig[ServerConfig]
|
||||
}
|
||||
|
||||
/** Database configuration
|
||||
*
|
||||
* @param host
|
||||
* Database host
|
||||
* @param port
|
||||
* Database port
|
||||
* @param database
|
||||
* Database name
|
||||
* @param user
|
||||
* Database user
|
||||
* @param password
|
||||
* Database password
|
||||
*/
|
||||
final case class DatabaseConfig(
|
||||
host: String,
|
||||
port: Int,
|
||||
database: String,
|
||||
user: String,
|
||||
password: String
|
||||
)
|
||||
|
||||
object DatabaseConfig {
|
||||
given config: Config[DatabaseConfig] = deriveConfig[DatabaseConfig]
|
||||
}
|
||||
|
||||
/** Application configuration
|
||||
*
|
||||
* Composed from server and database configurations. Uses zio-config-magnolia for automatic
|
||||
* derivation.
|
||||
*
|
||||
* @param server
|
||||
* Server configuration
|
||||
* @param database
|
||||
* Database configuration
|
||||
*/
|
||||
final case class AppConfig(
|
||||
server: ServerConfig,
|
||||
database: DatabaseConfig
|
||||
)
|
||||
|
||||
object AppConfig {
|
||||
given config: Config[AppConfig] = deriveConfig[AppConfig]
|
||||
}
|
||||
Reference in New Issue
Block a user