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