All checks were successful
/ Build and Release Library (push) Successful in 1m29s
Reviewed-on: #1
52 lines
1.3 KiB
Scala
52 lines
1.3 KiB
Scala
package gs.config.v0.source
|
|
|
|
import cats.Applicative
|
|
import cats.effect.Sync
|
|
import gs.config.v0.ConfigKey
|
|
|
|
/** Interface for loading raw configuration values.
|
|
*
|
|
* This interface is **not** intended to be used with sensitive information. Do
|
|
* not use this interface for loading passwords, encryption keys, or any other
|
|
* sensitive information.
|
|
*/
|
|
trait ConfigSource[F[_]]:
|
|
/** Retrieve the value for the specified key.
|
|
*
|
|
* @param key
|
|
* The key which defines the piece of configuration.
|
|
* @return
|
|
* The raw value, or an error if no value can be retrieved.
|
|
*/
|
|
def getValue(key: ConfigKey[?]): F[Option[String]]
|
|
|
|
/** @return
|
|
* The name of this source.
|
|
*/
|
|
def name: String
|
|
|
|
object ConfigSource:
|
|
|
|
def inMemory[F[_]: Applicative](
|
|
configs: Map[String, String]
|
|
): ConfigSource[F] =
|
|
new MemoryConfigSource[F](configs)
|
|
|
|
def environment[F[_]: Sync]: ConfigSource[F] =
|
|
new EnvironmentConfigSource[F]
|
|
|
|
def empty[F[_]: Applicative]: ConfigSource[F] =
|
|
new Empty[F]
|
|
|
|
final class Empty[F[_]: Applicative] extends ConfigSource[F]:
|
|
|
|
/** @inheritDocs
|
|
*/
|
|
override def getValue(key: ConfigKey[?]): F[Option[String]] =
|
|
Applicative[F].pure(None)
|
|
|
|
/** @inheritDocs
|
|
*/
|
|
override val name: String = "empty"
|
|
|
|
end ConfigSource
|