janvladimirmostert
11/12/2022, 9:01 PM@Suppress("EnumEntryName")
enum class ConfigUri(val raw: String) {
login("/login"),
logout("/logout"),
register("/register"),
verify("/verify/{hash}"),
reset1("/reset"),
reset2("/reset/{hash}")
;
fun verify.build(hash: String): String = raw.replace("{hash}", hash)
}
in the endpoints where I declare the GET / POST handlers, I want to be able to do GET(ConfigUri.login.raw)
and in places where I need to fill in the hashes for example when sending out an email with a verify link, I want to be able to do ConfigUri.verify.build(hash = generatedRandomHash)
to generate something like /verify/12344-1324234-sdfsdfs
janvladimirmostert
11/12/2022, 9:05 PM@Suppress("ClassName")
sealed class ConfigUri2(val raw: String) {
object login : ConfigUri2("/login")
object verify : ConfigUri2("/verify/{hash}") {
fun build(hash: String) = raw.replace("{hash}", hash)
}
}
the enums did look a lot cleaner thoughBhargav Mogra
11/13/2022, 4:15 AM