Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@

package io.ktor.server.config

import io.ktor.util.logging.*

internal expect val CONFIG_PATH: List<String>

private val logger = KtorSimpleLogger("io.ktor.server.config.ConfigLoader")

/**
* Loads an application configuration.
* An implementation of this interface should return [ApplicationConfig] if applicable configuration is found
Expand Down Expand Up @@ -51,23 +55,34 @@ public interface ConfigLoader {
*/
public fun load(path: String? = null): ApplicationConfig {
if (path == null) {
logger.debug("Loading default configuration")
val default = loadDefault()
if (default != null) return default
}

for (loader in configLoaders) {
logger.debug("Trying ConfigLoader: ${loader::class.simpleName}")
val config = loader.load(path)
if (config != null) return config
if (config != null) {
logger.debug("Configuration loaded successfully using ${loader::class.simpleName} from path: $path")
return config
}
}

logger.debug("No configuration found, using empty MapApplicationConfig")
return MapApplicationConfig()
}

private fun loadDefault(): ApplicationConfig? {
for (defaultPath in CONFIG_PATH) {
logger.debug("Trying default config path: $defaultPath")
for (loader in configLoaders) {
logger.debug("Trying ConfigLoader: ${loader::class.simpleName} for path: $defaultPath")
val config = loader.load(defaultPath)
if (config != null) return config
if (config != null) {
logger.debug("Default configuration loaded using ${loader::class.simpleName} from path: $defaultPath")
return config
}
}
}

Expand Down