Add a banner for ktor.
fun main() {
embeddedServer(Netty, port = 8000) {
banner {
bannerText = "Ktor Banner"
}
routing {
get("/") {
call.respondText("Hello, world!")
}
}
}.start(wait = true)
}
This will print:
_ ___ ____
| |/ / |_ ___ _ __ | __ ) __ _ _ __ _ __ ___ _ __
| ' /| __/ _ \| '__| | _ \ / _` | '_ \| '_ \ / _ \ '__|
| . \| || (_) | | | |_) | (_| | | | | | | | __/ |
|_|\_\\__\___/|_| |____/ \__,_|_| |_|_| |_|\___|_|
banner {
bannerText = "Ktor Banner"
// custom font
loadFigFont = {
val inputStream = ::main.javaClass.classLoader.getResourceAsStream("starwars.flf")
FigFont.loadFigFont(inputStream)
}
// custom render
render {
println(it.text)
}
// append custom footer
beforeBanner { banner ->
println("".padEnd(banner.width, '-'))
}
// append custom footer
afterBanner { banner ->
val title = " MyKtorApp v1.2.3 "
val homepage = "https://yi.team/"
val filling = "".padEnd(banner.width - title.length - homepage.length, ' ')
println("".padEnd(banner.width, '-'))
println("$title$filling$homepage")
}
}
This will print:
-------------------------------------------------------------------------------------------------------------------
__ ___ .___________. ______ .______ .______ ___ .__ __. .__ __. _______ .______
| |/ / | | / __ \ | _ \ | _ \ / \ | \ | | | \ | | | ____|| _ \
| ' / `---| |----`| | | | | |_) | | |_) | / ^ \ | \| | | \| | | |__ | |_) |
| < | | | | | | | / | _ < / /_\ \ | . ` | | . ` | | __| | /
| . \ | | | `--' | | |\ \----. | |_) | / _____ \ | |\ | | |\ | | |____ | |\ \----.
|__|\__\ |__| \______/ | _| `._____| |______/ /__/ \__\ |__| \__| |__| \__| |_______|| _| `._____|
-------------------------------------------------------------------------------------------------------------------
MyKtorApp v1.2.3 https://yi.team/
fun main() {
embeddedServer(Netty, port = 8000) {
banner {
bannerText = "Ktor Banner"
}
routing {
get("/") {
call.respondText("Hello, world!")
}
}
}.start(wait = true)
}
This will print:
@ymind, full stack engineer.
This is open-sourced software licensed under the MIT license.