aboutsummaryrefslogblamecommitdiff
path: root/src/main/scala/xyz/driver/core/config.scala
blob: be814089223c60700588bce5171d632cd0b5e077 (plain) (tree)
1
2
3
4
5
6
7
8
9
                       



                                                  

               
                                   
                                                                                             
 
                                                                                                     
 
                            
                                           
                                  



                                                                          
 
                                 
     

   
package xyz.driver.core

import java.io.File
import com.typesafe.config.{Config, ConfigFactory}

object config {

  def loadDefaultConfig: Config = {
    val configDefaults = ConfigFactory.load(this.getClass.getClassLoader, "application.conf")

    scala.sys.env.get("APPLICATION_CONFIG").orElse(scala.sys.props.get("application.config")) match {

      case Some(filename) =>
        val configFile = new File(filename)
        if (configFile.exists()) {
          ConfigFactory.parseFile(configFile).withFallback(configDefaults)
        } else {
          throw new IllegalStateException(s"No config found at $filename")
        }

      case None => configDefaults
    }
  }
}