Skip to content

wozaki/sisioh-config

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sisioh config

sisioh-config is scala wrapper for typesafe config.

setup

Build Configuration

for build.sbt

resolvers ++= Seq(
  // ...
  // for snapshot
  "Sonatype Snapshot Repository" at "https://oss.sonatype.org/content/repositories/snapshots/",
  // ...
)

libraryDependencies ++= Seq(
  // ...
  "org.sisioh" %% "sisioh-config" % "0.0.2-SNAPSHOT",
  // ...
)

for Build.scala

object AppBuild extends Build {
  val root = Project(
    id = "app",
    base = file("."),
    resolvers ++= Seq(
      // ...
      // for snapshot
      "Sonatype Snapshot Repository" at "https://oss.sonatype.org/content/repositories/snapshots/",
      // ...
    ),
    settings = Project.defaultSettings ++ Seq(
      libraryDependencies ++= Seq(
        // ...
        "org.sisioh" %% "sisioh-config" % "0.0.2-SNAPSHOT",
        // ...
      )
    )
  )
}

usage

read raw value

conf/application.conf

foo.bar1 = value1
foo.bar2 = value2
foo.bar3 = 1
val config = Configuration.parseFile(new File("conf/application.conf"))
val Some(bar1) = config.getStringValue("foo.bar1") // value1
val Some(bar2) = config.getStringValue("foo.bar2") // value2
val Some(bar3) = config.getIntValue("foo.bar3") // 1

read raw value as Seq

conf/application.conf

foo = [value1, value2]
val config = Configuration.parseFile(new File("conf/application.conf"))
val Some(values) = config.getStringValues("foo") // Seq(value1, value2)

read ConfigurationValue

conf/application.conf

foo.bar1 = value1
foo.bar2 = value2
foo.bar3 = 1
val config = Configuration.parseFile(new File("conf/application.conf"))
val Some(bar1ConfigValue) = config.getConfigurationValue("foo.bar1")
val Some(bar1) = bar1ConfigValue.valueAsString // value1
// ...

read Configuration

conf/application.conf

foo.bar1 = value1
foo.bar2 = value2
foo.bar3 = 1
val config = Configuration.parseFile(new File("conf/application.conf"))
val Some(foo) = config.getConfiguration("foo")
val Some(bar1) = foo.getStringValue("bar1") // value1
val Some(bar2) = foo.getStringValue("bar2") // value2
val Some(bar3) = foo.getIntValue("bar3") // 1

read ConfigurationObject

conf/application.conf

db = { driverClassName: com.mysql.jdbc.Driver, url: jdbc:mysql://localhost/test }
val config = Configuration.parseFile(new File("conf/application.conf"))
val Some(dbConfigObject) = config.getConfigurationObject("db")
val Some(driverClassName) = dbConfigObject.get("driverClassName") // com.mysql.jdbc.Driver
val Some(url) = dbConfigObject.get("url") // jdbc:mysql://localhost/test

About

the scala wrapper for typesafe config

Resources

License

Stars

Watchers

Forks

Packages

No packages published