Skip to content

generate config objects for typesafe.config in scala

License

Notifications You must be signed in to change notification settings

cornerman/autoconfig

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

autoconfig

generate config objects for typesafe.config in scala

usage

Dependency in build.sbt:

resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"

libraryDependencies += "com.github.cornerman" %% "autoconfig" % "0.1.0-SNAPSHOT"

addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.full)

example

Code:

import autoconfig.config
import java.time.Duration

case class UserGroup(id: Long) extends AnyVal
case class SmtpConfig(endpoint: String, username: String, password: String)
case class AuthConfig(tokenLifetime: Duration, secret: String)
class EmailConfig(fromAddress: String, smtp: SmtpConfig)

@config(section = "wust") object Config {
  val usergroup: UserGroup
  val auth: AuthConfig
  val email: Option[EmailConfig]

  def hasMail = email.isDefined
}

application.conf:

wust {
    usergroup = 1
    auth {
        tokenLifetime = 24h
        secret = ${SECRET}
    }

    email {
        fromAddress = ${?EMAIL_ADDRESS}
        smtp {
            username = ${?SMTP_USER}
            password = ${?SMTP_PASS}
            endpoint = ${?SMTP_ENDPOINT}
        }
    }
}

About

generate config objects for typesafe.config in scala

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages