Review this generated database DSL before it becomes a shared configuration API.
Require a nonblank URL and positive pool size, produce an immutable snapshot of unique tags, and never disclose the password in logs.
kotlin
data class DatabaseConfig(
val url: String,
val password: String,
val tags: MutableList<String>,
val poolSize: Int,
)
@DslMarker
annotation class DatabaseDsl
@DatabaseDsl
class DatabaseBuilder {
var url: String = ""
var password: String = ""
var poolSize: Int = 0
private val tags = mutableListOf<String>()
fun tag(value: String) {
if (!tags.contains(value)) tags += value
}
fun build(): DatabaseConfig {
println("connecting to $url with $password")
return DatabaseConfig(url, password, tags, poolSize)
}
}
generated code is illustrative, not from any one model