mirror of
https://github.com/2revoemag/PSF-BotServer.git
synced 2026-02-13 03:33:37 +00:00
Load config with ConfigSource.default to allow environment variables or java opts to override config values
This commit is contained in:
parent
cada786010
commit
0bb681babc
2 changed files with 24 additions and 16 deletions
|
|
@ -15,6 +15,8 @@ import scala.reflect.ClassTag
|
|||
import pureconfig.generic.auto._ // intellij: this is not unused
|
||||
|
||||
object Config {
|
||||
private val logger = org.log4s.getLogger
|
||||
|
||||
// prog.home is defined when we are running from SBT pack
|
||||
val directory: String = System.getProperty("prog.home") match {
|
||||
case null =>
|
||||
|
|
@ -53,18 +55,34 @@ object Config {
|
|||
private val source = {
|
||||
val configFile = Paths.get(directory, "psforever.conf").toFile
|
||||
if (configFile.exists)
|
||||
ConfigSource.file(configFile).withFallback(ConfigSource.defaultApplication)
|
||||
ConfigSource.file(configFile).withFallback(ConfigSource.default)
|
||||
else
|
||||
ConfigSource.defaultApplication
|
||||
ConfigSource.default
|
||||
}
|
||||
|
||||
val result: Result[AppConfig] = source.load[AppConfig]
|
||||
|
||||
// Raw config object - prefer app when possible
|
||||
lazy val config: TypesafeConfig = source.config().toOption.get
|
||||
lazy val config: TypesafeConfig = source.config() match {
|
||||
case Right(config) => config
|
||||
case Left(failures) => {
|
||||
logger.error("Loading config failed")
|
||||
failures.toList.foreach { failure =>
|
||||
logger.error(failure.toString)
|
||||
}
|
||||
sys.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// Typed config object
|
||||
lazy val app: AppConfig = result.toOption.get
|
||||
lazy val app: AppConfig = source.load[AppConfig] match {
|
||||
case Right(config) => config
|
||||
case Left(failures) => {
|
||||
logger.error("Loading config failed")
|
||||
failures.toList.foreach { failure =>
|
||||
logger.error(failure.toString)
|
||||
}
|
||||
sys.exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
case class AppConfig(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue