refactor for repeated code

pull/1210/head
gregchalmers 2021-03-09 00:35:51 -08:00
parent c09f9a675f
commit f25c667a8a
1 changed files with 19 additions and 37 deletions

56
app.go
View File

@ -894,47 +894,29 @@ func (app *App) startupMessage(addr string, tls bool, pids string) {
procs = "1"
}
var mainLogo string
mainLogo := cBlack+
" ┌───────────────────────────────────────────────────┐\n"+
" │ "+centerValue(" Fiber v"+Version, 49)+" │\n"
if host == "0.0.0.0" {
const logo string = "%s" +
" ┌───────────────────────────────────────────────────┐\n" +
" │ %s │\n" +
" │ %s │\n" +
" │ %s │\n" +
" │ │\n" +
" │ Handlers %s Processes %s │\n" +
" │ Prefork .%s PID ....%s │\n" +
" └───────────────────────────────────────────────────┘" +
"%s"
mainLogo = fmt.Sprintf(logo,
cBlack,
centerValue(" Fiber v"+Version, 49),
center(fmt.Sprintf("%s://127.0.0.1:%s", scheme, port), 49),
center(fmt.Sprintf("bound %s://%s:%s", scheme, host, port), 49),
value(strconv.Itoa(app.handlerCount), 14), value(procs, 12),
value(isPrefork, 14), value(strconv.Itoa(os.Getpid()), 14),
cReset,
)
mainLogo +=
" │ "+center(fmt.Sprintf("%s://127.0.0.1:%s", scheme, port), 49)+ " │\n" +
" │ "+center(fmt.Sprintf("bound %s://0.0.0.0:%s", scheme, port), 49)+ " │\n"
} else {
const logo string = "%s" +
" ┌───────────────────────────────────────────────────┐\n" +
" │ %s │\n" +
" │ %s │\n" +
" │ │\n" +
" │ Handlers %s Processes %s │\n" +
" │ Prefork .%s PID ....%s │\n" +
" └───────────────────────────────────────────────────┘" +
"%s"
mainLogo = fmt.Sprintf(logo,
cBlack,
centerValue(" Fiber v"+Version, 49),
center(fmt.Sprintf("%s://%s:%s", scheme, host, port), 49),
value(strconv.Itoa(app.handlerCount), 14), value(procs, 12),
value(isPrefork, 14), value(strconv.Itoa(os.Getpid()), 14),
cReset,
)
mainLogo +=
" │ "+center(fmt.Sprintf("%s://%s:%s", scheme, host, port), 49)+ " │\n"
}
mainLogo += fmt.Sprintf(
" │ │\n"+
" │ Handlers %s Processes %s │\n"+
" │ Prefork .%s PID ....%s │\n"+
" └───────────────────────────────────────────────────┘"+
cReset,
value(strconv.Itoa(app.handlerCount), 14), value(procs, 12),
value(isPrefork, 14), value(strconv.Itoa(os.Getpid()), 14),
)
var childPidsLogo string
if app.config.Prefork {
var childPidsTemplate string