Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎈 prepare for v1.15.0 #744

Merged
merged 1 commit into from
Sep 1, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 29 additions & 29 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"bufio"
"crypto/tls"
"fmt"
"io"
"net"
"net/http"
"net/http/httputil"
Expand All @@ -22,7 +23,6 @@ import (
"strconv"
"strings"
"sync"
"text/tabwriter"
"time"

utils "github.com/gofiber/utils"
Expand All @@ -32,7 +32,7 @@ import (
)

// Version of current package
const Version = "1.14.4"
const Version = "1.14.5"

// Map is a shortcut for map[string]interface{}, useful for JSON returns
type Map map[string]interface{}
Expand All @@ -48,6 +48,7 @@ type Error struct {

// App denotes the Fiber application.
type App struct {
out io.Writer
mutex sync.Mutex
// Route stack divided by HTTP methods
stack [][]*Route
Expand Down Expand Up @@ -428,12 +429,6 @@ func (app *App) Routes() []*Route {
return routes
}

// Serve is deprecated, please use app.Listener()
func (app *App) Serve(ln net.Listener, tlsconfig ...*tls.Config) error {
fmt.Println("serve: app.Serve() is deprecated since v1.12.5, please use app.Listener()")
return app.Listener(ln, tlsconfig...)
}

// Listener can be used to pass a custom listener.
// You can pass an optional *tls.Config to enable TLS.
// This method does not support the Prefork feature
Expand Down Expand Up @@ -511,7 +506,8 @@ func (app *App) Stack() [][]*Route {
return app.stack
}

// Shutdown gracefully shuts down the server without interrupting any active connections.
// Shutdown gracefully
// shuts down the server without interrupting any active connections.
// Shutdown works by first closing all open listeners and then waiting indefinitely for all connections to return to idle and then shut down.
//
// When Shutdown is called, Serve, ListenAndServe, and ListenAndServeTLS immediately return nil.
Expand Down Expand Up @@ -645,9 +641,9 @@ func (app *App) init() *App {

const (
cBlack = "\u001b[90m"
// cRed = "\u001b[91m"
// cGreen = "\u001b[92m"
// cYellow = "\u001b[93m"
cRed = "\u001b[91m"
// cGreen = "\u001b[92m"
// cYellow = "\u001b[93m"
// cBlue = "\u001b[94m"
// cMagenta = "\u001b[95m"
cCyan = "\u001b[96m"
Expand All @@ -666,17 +662,20 @@ func (app *App) startupMessage(addr string, tls bool, pids string) {
logo += `%s ____%s / ____(_) /_ ___ _____ %s` + "\n"
logo += `%s_____%s / /_ / / __ \/ _ \/ ___/ %s` + "\n"
logo += `%s __%s / __/ / / /_/ / __/ / %s` + "\n"
logo += `%s /_/ /_/_.___/\___/_/%s %s` + "\n"

logo += `%s /_/ /_/_.___/\___/_/%s %s` + ""
logo += cRed + "v1.15.0 will be released on 15 September 2020 and contains breaking changes!\nPlease visit https://github.com/gofiber/fiber/issues/736 for more information.\n" + cReset
host, port := parseAddr(addr)
padding := strconv.Itoa(len(host))
if len(host) <= 4 {
padding = "5"
}
var (
tlsStr = "FALSE"
preforkStr = "FALSE"
handlerCount = app.handlerCount
handlerCount = strconv.Itoa(app.handlerCount)
osName = utils.ToUpper(runtime.GOOS)

cpuThreads = runtime.NumCPU()
pid = os.Getpid()
cpuThreads = runtime.NumCPU()
pid = os.Getpid()
)
if host == "" {
host = "0.0.0.0"
Expand All @@ -689,25 +688,26 @@ func (app *App) startupMessage(addr string, tls bool, pids string) {
}
// tabwriter makes sure the spacing are consistent across different values
// colorable handles the escape sequence for stdout using ascii color codes
var out *tabwriter.Writer
host = fmt.Sprintf("%-"+padding+"s", host)
port = fmt.Sprintf("%-"+padding+"s", port)
tlsStr = fmt.Sprintf("%-"+padding+"s", tlsStr)
handlerCount = fmt.Sprintf("%-"+padding+"s", handlerCount)

app.out = colorable.NewColorableStdout()
// Check if colors are supported
if os.Getenv("TERM") == "dumb" ||
(!isatty.IsTerminal(os.Stdout.Fd()) && !isatty.IsCygwinTerminal(os.Stdout.Fd())) {
out = tabwriter.NewWriter(colorable.NewNonColorable(os.Stdout), 0, 0, 2, ' ', 0)
} else {
out = tabwriter.NewWriter(colorable.NewColorableStdout(), 0, 0, 2, ' ', 0)
app.out = colorable.NewNonColorable(os.Stdout)
}
// simple Sprintf function that defaults back to black
cyan := func(v interface{}) string {
return fmt.Sprintf("%s%v%s", cCyan, v, cBlack)
}
// 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\tPREFORK %s", cyan(tlsStr), cyan(preforkStr)),
cBlack, cyan(Version), fmt.Sprintf(" HANDLERS %s\t\t\t PID %s%s%s\n", cyan(handlerCount), cyan(pid), pids, cReset),
fmt.Fprintf(app.out, logo, cBlack, cBlack,
cCyan, cBlack, fmt.Sprintf(" HOST %s OS %s", cyan(host), cyan(osName)),
cCyan, cBlack, fmt.Sprintf(" PORT %s THREADS %s", cyan(port), cyan(cpuThreads)),
cCyan, cBlack, fmt.Sprintf(" TLS %s PREFORK %s", cyan(tlsStr), cyan(preforkStr)),
cBlack, cyan(Version), fmt.Sprintf(" HANDLERS %s PID %s%s%s\n", cyan(handlerCount), cyan(pid), pids, cReset),
)
// Write to io.write
_ = out.Flush()
}