mirror of https://github.com/gofiber/fiber.git
Update startupMessage
parent
67fefdd5d8
commit
45aacc1ddb
53
app.go
53
app.go
|
@ -15,13 +15,16 @@ import (
|
|||
"net/http/httputil"
|
||||
"os"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"text/tabwriter"
|
||||
"time"
|
||||
|
||||
utils "github.com/gofiber/utils"
|
||||
colorable "github.com/segrey/go-colorable"
|
||||
fasthttp "github.com/valyala/fasthttp"
|
||||
fprefork "github.com/valyala/fasthttp/prefork"
|
||||
)
|
||||
|
@ -419,7 +422,7 @@ func (app *App) Serve(ln net.Listener, tlsconfig ...*tls.Config) error {
|
|||
}
|
||||
// Print startup message
|
||||
if !app.Settings.DisableStartupMessage {
|
||||
startupMessage(ln.Addr().String())
|
||||
app.startupMessage(ln.Addr().String())
|
||||
}
|
||||
|
||||
return app.server.Serve(ln)
|
||||
|
@ -442,12 +445,12 @@ func (app *App) Listen(address interface{}, tlsconfig ...*tls.Config) error {
|
|||
}
|
||||
// Update fiber server settings
|
||||
app.init()
|
||||
// Print startup message
|
||||
if !app.Settings.DisableStartupMessage {
|
||||
app.startupMessage(addr)
|
||||
}
|
||||
// Start prefork
|
||||
if app.Settings.Prefork {
|
||||
// Print startup message
|
||||
if !app.Settings.DisableStartupMessage {
|
||||
startupMessage(addr)
|
||||
}
|
||||
pf := fprefork.New(app.server) // fasthttp/prefork
|
||||
pf.Reuseport = true
|
||||
pf.Network = "tcp4"
|
||||
|
@ -468,10 +471,10 @@ func (app *App) Listen(address interface{}, tlsconfig ...*tls.Config) error {
|
|||
if len(tlsconfig) > 0 {
|
||||
ln = tls.NewListener(ln, tlsconfig[0])
|
||||
}
|
||||
// Print startup message
|
||||
if !app.Settings.DisableStartupMessage {
|
||||
startupMessage(ln.Addr().String())
|
||||
}
|
||||
// // Print startup message
|
||||
// if !app.Settings.DisableStartupMessage {
|
||||
// app.startupMessage(ln.Addr().String())
|
||||
// }
|
||||
// Start listening
|
||||
return app.server.Serve(ln)
|
||||
}
|
||||
|
@ -609,11 +612,35 @@ func (app *App) init() *App {
|
|||
return app
|
||||
}
|
||||
|
||||
func startupMessage(addr string) {
|
||||
const (
|
||||
cBlack = "\u001b[90m"
|
||||
cRed = "\u001b[91m"
|
||||
cGreen = "\u001b[92m"
|
||||
cYellow = "\u001b[93m"
|
||||
cBlue = "\u001b[94m"
|
||||
cMagenta = "\u001b[95m"
|
||||
cCyan = "\u001b[96m"
|
||||
cWhite = "\u001b[97m"
|
||||
cReset = "\u001b[0m"
|
||||
)
|
||||
|
||||
func (app *App) startupMessage(port string) {
|
||||
out := tabwriter.NewWriter(colorable.NewColorableStdout(), 0, 8, 0, ' ', 0)
|
||||
if fprefork.IsChild() {
|
||||
fmt.Printf("Launched child proc #%v\n", os.Getpid())
|
||||
// rand.Seed(time.Now().UnixNano())
|
||||
// r := rand.Intn(100)
|
||||
// time.Sleep(time.Duration(r) * time.Millisecond)
|
||||
fmt.Fprintf(out, "%sChild PID: %s#%v%s\n", cBlack, cGreen, os.Getpid(), cReset)
|
||||
} else {
|
||||
fmt.Printf(" _______ __\n ____ / ____(_) /_ ___ _____\n_____ / /_ / / __ \\/ _ \\/ ___/\n __ / __/ / / /_/ / __/ /\n /_/ /_/_.___/\\___/_/ v%s\n", Version)
|
||||
fmt.Printf("Started listening on %s\n", addr)
|
||||
fmt.Fprintf(out, "%s ___ __ ___ __ \n|__ | |__) |__ |__)\n| | |__) |___ | \\", cGreen)
|
||||
fmt.Fprintf(out, "%sv%s\n", cBlack, Version)
|
||||
fmt.Fprintf(out, "PORT: %s%s%s \tROUTES: %s%v%s\n", cGreen, port, cBlack, cGreen, len(app.Routes()), cBlack)
|
||||
fmt.Fprintf(out, "PPID: %s%v%s \tPREFORK: %s%v%s\n", cGreen, os.Getppid(), cBlack, cGreen, app.Settings.Prefork, cBlack)
|
||||
fmt.Fprintf(out, "OS: %s%v %v %v cores%s\n\n", cGreen, runtime.GOOS, runtime.GOARCH, runtime.NumCPU(), cReset)
|
||||
//fmt.Fprintf(out, "\n%sFiber v%s listening on %s%s", cGreen, Version, addr, cReset)
|
||||
//fmt.Fprintf(out, "\n%sMain process #%v%s", cBlack, os.Getppid(), cReset)
|
||||
//fmt.Printf(" _______ __\n ____ / ____(_) /_ ___ _____\n_____ / /_ / / __ \\/ _ \\/ ___/\n __ / __/ / / /_/ / __/ /\n /_/ /_/_.___/\\___/_/ v%s\n", Version)
|
||||
// fmt.Printf("Started listening on %s\n", addr)
|
||||
}
|
||||
out.Flush()
|
||||
}
|
||||
|
|
1
go.mod
1
go.mod
|
@ -5,6 +5,7 @@ go 1.11
|
|||
require (
|
||||
github.com/gofiber/utils v0.0.6
|
||||
github.com/gorilla/schema v1.1.0
|
||||
github.com/segrey/go-colorable v0.1.8
|
||||
github.com/valyala/bytebufferpool v1.0.0
|
||||
github.com/valyala/fasthttp v1.14.0
|
||||
)
|
||||
|
|
7
go.sum
7
go.sum
|
@ -6,6 +6,10 @@ github.com/gorilla/schema v1.1.0 h1:CamqUDOFUBqzrvxuz2vEwo8+SUdwsluFh7IlzJh30LY=
|
|||
github.com/gorilla/schema v1.1.0/go.mod h1:kgLaKoK1FELgZqMAVxx/5cbj0kT+57qxUrAlIO2eleU=
|
||||
github.com/klauspost/compress v1.10.4 h1:jFzIFaf586tquEB5EhzQG0HwGNSlgAJpG53G6Ss11wc=
|
||||
github.com/klauspost/compress v1.10.4/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
|
||||
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
|
||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/segrey/go-colorable v0.1.8 h1:UVuWIiT7W9xV25H69N1a0znYOZK0xVRgeoG1DrIJFNk=
|
||||
github.com/segrey/go-colorable v0.1.8/go.mod h1:9Gc/K8hJlvkFa0LKZlvsMh2I0nmgzunt/qoMtbsRi3M=
|
||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
github.com/valyala/fasthttp v1.14.0 h1:67bfuW9azCMwW/Jlq/C+VeihNpAuJMWkYPBig1gdi3A=
|
||||
|
@ -16,5 +20,8 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90Pveol
|
|||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884=
|
||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
|
|
Loading…
Reference in New Issue