Replace route count with handler count

Co-Authored-By: RW <renewerner87@googlemail.com>
Co-Authored-By: kiyon <kiyonlin@users.noreply.github.com>
pull/662/head
Fenny 2020-07-22 02:06:32 +02:00
parent 0cbe432ee0
commit 62dc7749e2
1 changed files with 13 additions and 18 deletions

31
app.go
View File

@ -19,7 +19,6 @@ import (
"os"
"reflect"
"runtime"
"sort"
"strconv"
"strings"
"sync"
@ -33,7 +32,7 @@ import (
)
// Version of current package
const Version = "1.13.2"
const Version = "1.13.3"
// Map is a shortcut for map[string]interface{}, useful for JSON returns
type Map map[string]interface{}
@ -52,8 +51,8 @@ type App struct {
mutex sync.Mutex
// Route stack divided by HTTP methods
stack [][]*Route
// Amount of registered routes
routesCount int
// Amount of registered handlers
handlerCount int
// Ctx pool
pool sync.Pool
// Fasthttp server
@ -425,10 +424,6 @@ func (app *App) Routes() []*Route {
routes = append(routes, app.stack[m][r])
}
}
// Sort routes by stack position
sort.Slice(routes, func(i, k int) bool {
return routes[i].pos < routes[k].pos
})
return routes
}
@ -674,12 +669,12 @@ func (app *App) startupMessage(addr string, tls bool, pids string) {
host, port := parseAddr(addr)
var (
tlsStr = "FALSE"
routesLen = len(app.Routes())
osName = utils.ToUpper(runtime.GOOS)
memTotal = utils.ByteSize(utils.MemoryTotal())
cpuThreads = runtime.NumCPU()
pid = os.Getpid()
tlsStr = "FALSE"
handlerCount = app.handlerCount
osName = utils.ToUpper(runtime.GOOS)
memTotal = utils.ByteSize(utils.MemoryTotal())
cpuThreads = runtime.NumCPU()
pid = os.Getpid()
)
if host == "" {
host = "0.0.0.0"
@ -703,10 +698,10 @@ func (app *App) startupMessage(addr string, tls bool, pids string) {
}
// Build startup banner
fmt.Fprintf(out, logo, cBlack, cBlack,
cCyan, cBlack, fmt.Sprintf(" HOST %s\tOS %s", cyan(host), cyan(osName)),
cCyan, cBlack, fmt.Sprintf(" PORT %s\tTHREADS %s", cyan(port), cyan(cpuThreads)),
cCyan, cBlack, fmt.Sprintf(" TLS %s\tMEM %s", cyan(tlsStr), cyan(memTotal)),
cBlack, cyan(Version), fmt.Sprintf(" ROUTES %s\t\t\t PID %s%s%s\n", cyan(routesLen), cyan(pid), pids, cReset),
cCyan, cBlack, fmt.Sprintf(" HOST %s\tOS %s", cyan(host), cyan(osName)),
cCyan, cBlack, fmt.Sprintf(" PORT %s\tTHREADS %s", cyan(port), cyan(cpuThreads)),
cCyan, cBlack, fmt.Sprintf(" TLS %s\tMEM %s", cyan(tlsStr), cyan(memTotal)),
cBlack, cyan(Version), fmt.Sprintf(" HANDLERS %s\t\t\t PID %s%s%s\n", cyan(handlerCount), cyan(pid), pids, cReset),
)
// Write to io.write
_ = out.Flush()