mirror of https://github.com/gofiber/fiber.git
📦 Add child PID display when prefork enabled
parent
53ab7a63bc
commit
35e100db6e
109
app.go
109
app.go
|
@ -693,7 +693,7 @@ func (app *App) startupMessage(addr string, tls bool, pids string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var logo string
|
var logo string
|
||||||
logo += "\n%s"
|
logo += "%s"
|
||||||
logo += " ┌───────────────────────────────────────────────────┐\n"
|
logo += " ┌───────────────────────────────────────────────────┐\n"
|
||||||
logo += " │ %s │\n"
|
logo += " │ %s │\n"
|
||||||
logo += " │ %s │\n"
|
logo += " │ %s │\n"
|
||||||
|
@ -701,7 +701,7 @@ func (app *App) startupMessage(addr string, tls bool, pids string) {
|
||||||
logo += " │ Handlers %s Threads %s │\n"
|
logo += " │ Handlers %s Threads %s │\n"
|
||||||
logo += " │ Prefork .%s PID ....%s │\n"
|
logo += " │ Prefork .%s PID ....%s │\n"
|
||||||
logo += " └───────────────────────────────────────────────────┘"
|
logo += " └───────────────────────────────────────────────────┘"
|
||||||
logo += "%s\n\n"
|
logo += "%s"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
cBlack = "\u001b[90m"
|
cBlack = "\u001b[90m"
|
||||||
|
@ -751,6 +751,15 @@ func (app *App) startupMessage(addr string, tls bool, pids string) {
|
||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pad := func(s string, width int) (str string) {
|
||||||
|
toAdd := width - len(s)
|
||||||
|
str += s
|
||||||
|
for i := 0; i < toAdd; i++ {
|
||||||
|
str += " "
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
host, port := parseAddr(addr)
|
host, port := parseAddr(addr)
|
||||||
if host == "" || host == "0.0.0.0" {
|
if host == "" || host == "0.0.0.0" {
|
||||||
host = "127.0.0.1"
|
host = "127.0.0.1"
|
||||||
|
@ -765,11 +774,7 @@ func (app *App) startupMessage(addr string, tls bool, pids string) {
|
||||||
isPrefork = "Enabled"
|
isPrefork = "Enabled"
|
||||||
}
|
}
|
||||||
|
|
||||||
out := colorable.NewColorableStdout()
|
mainLogo := fmt.Sprintf(logo,
|
||||||
if os.Getenv("TERM") == "dumb" || (!isatty.IsTerminal(os.Stdout.Fd()) && !isatty.IsCygwinTerminal(os.Stdout.Fd())) {
|
|
||||||
out = colorable.NewNonColorable(os.Stdout)
|
|
||||||
}
|
|
||||||
_, _ = fmt.Fprintf(out, logo,
|
|
||||||
cBlack,
|
cBlack,
|
||||||
centerValue(" Fiber v"+Version, 49),
|
centerValue(" Fiber v"+Version, 49),
|
||||||
center(addr, 49),
|
center(addr, 49),
|
||||||
|
@ -778,4 +783,94 @@ func (app *App) startupMessage(addr string, tls bool, pids string) {
|
||||||
cReset,
|
cReset,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var childPidsLogo string
|
||||||
|
if app.config.Prefork {
|
||||||
|
var childPidsTemplate string
|
||||||
|
childPidsTemplate += "%s"
|
||||||
|
childPidsTemplate += " ┌───────────────────────────────────────────────────┐\n%s"
|
||||||
|
childPidsTemplate += " └───────────────────────────────────────────────────┘"
|
||||||
|
childPidsTemplate += "%s"
|
||||||
|
|
||||||
|
newLine := " │ %s%s%s │"
|
||||||
|
|
||||||
|
// Turn the `pids` variable (in the form ",a,b,c,d,e,f,etc") into a slice of PIDs
|
||||||
|
var pidSlice []string
|
||||||
|
for _, v := range strings.Split(pids, ",") {
|
||||||
|
if v != "" {
|
||||||
|
pidSlice = append(pidSlice, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var lines []string
|
||||||
|
thisLine := "Child PIDs ... "
|
||||||
|
var itemsOnThisLine []string
|
||||||
|
|
||||||
|
addLine := func() {
|
||||||
|
lines = append(lines,
|
||||||
|
fmt.Sprintf(
|
||||||
|
newLine,
|
||||||
|
cBlack,
|
||||||
|
thisLine+cCyan+pad(strings.Join(itemsOnThisLine, ", "), 49-len(thisLine)),
|
||||||
|
cBlack,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, pid := range pidSlice {
|
||||||
|
if len(thisLine+strings.Join(append(itemsOnThisLine, pid), ", ")) > 49 {
|
||||||
|
addLine()
|
||||||
|
thisLine = ""
|
||||||
|
itemsOnThisLine = []string{}
|
||||||
|
} else {
|
||||||
|
itemsOnThisLine = append(itemsOnThisLine, pid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add left over items to their own line
|
||||||
|
if len(itemsOnThisLine) != 0 {
|
||||||
|
addLine()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Form logo
|
||||||
|
childPidsLogo = fmt.Sprintf(childPidsTemplate,
|
||||||
|
cBlack,
|
||||||
|
strings.Join(lines, "\n")+"\n",
|
||||||
|
cReset,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Combine both the child PID logo and the main Fiber logo
|
||||||
|
|
||||||
|
// Pad the shorter logo to the length of the longer one
|
||||||
|
splitMainLogo := strings.Split(mainLogo, "\n")
|
||||||
|
splitChildPidsLogo := strings.Split(childPidsLogo, "\n")
|
||||||
|
|
||||||
|
mainLen := len(splitMainLogo)
|
||||||
|
childLen := len(splitChildPidsLogo)
|
||||||
|
|
||||||
|
if mainLen > childLen {
|
||||||
|
diff := mainLen - childLen
|
||||||
|
for i := 0; i < diff; i++ {
|
||||||
|
splitChildPidsLogo = append(splitChildPidsLogo, "")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
diff := childLen - mainLen
|
||||||
|
for i := 0; i < diff; i++ {
|
||||||
|
splitMainLogo = append(splitMainLogo, "")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Combine the two logos, line by line
|
||||||
|
output := "\n"
|
||||||
|
for i := range splitMainLogo {
|
||||||
|
output += cBlack + splitMainLogo[i] + " " + splitChildPidsLogo[i] + "\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
out := colorable.NewColorableStdout()
|
||||||
|
if os.Getenv("TERM") == "dumb" || (!isatty.IsTerminal(os.Stdout.Fd()) && !isatty.IsCygwinTerminal(os.Stdout.Fd())) {
|
||||||
|
out = colorable.NewNonColorable(os.Stdout)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Fprintln(out, output)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue