Merge pull request #599 from Fenny/master

🧹 House keeping
pull/603/head
fenny 2020-07-13 09:45:54 -04:00 committed by GitHub
commit e8c24762ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 3 deletions

2
app.go
View File

@ -658,7 +658,7 @@ func (app *App) startupMessage(addr string, tls bool, pids string) {
if app.IsChild() { if app.IsChild() {
return return
} }
// // ascii logo
var logo string var logo string
logo += `%s _______ __ %s` + "\n" logo += `%s _______ __ %s` + "\n"
logo += `%s ____%s / ____(_) /_ ___ _____ %s` + "\n" logo += `%s ____%s / ____(_) /_ ___ _____ %s` + "\n"

View File

@ -639,6 +639,7 @@ func Test_App_Next_Method(t *testing.T) {
utils.AssertEqual(t, 404, resp.StatusCode, "Status code") utils.AssertEqual(t, 404, resp.StatusCode, "Status code")
} }
// go test -run Test_App_Listen
func Test_App_Listen(t *testing.T) { func Test_App_Listen(t *testing.T) {
app := New(&Settings{ app := New(&Settings{
DisableStartupMessage: true, DisableStartupMessage: true,
@ -658,6 +659,7 @@ func Test_App_Listen(t *testing.T) {
utils.AssertEqual(t, nil, app.Listen("4010")) utils.AssertEqual(t, nil, app.Listen("4010"))
} }
// go test -run Test_App_Listener
func Test_App_Listener(t *testing.T) { func Test_App_Listener(t *testing.T) {
app := New(&Settings{ app := New(&Settings{
DisableStartupMessage: true, DisableStartupMessage: true,

4
ctx.go
View File

@ -257,7 +257,7 @@ func (ctx *Ctx) BodyParser(out interface{}) error {
} }
// query params // query params
if ctx.Fasthttp.QueryArgs().Len() > 0 { if ctx.Fasthttp.QueryArgs().Len() > 0 {
log.Println("Converting querystring using BodyParser will be deprecated, please use ctx.QueryParser") fmt.Println("Parsing query strings using `BodyParser` is deprecated since v1.12.7, please us `ctx.QueryParser` instead")
data := make(map[string][]string) data := make(map[string][]string)
ctx.Fasthttp.QueryArgs().VisitAll(func(key []byte, val []byte) { ctx.Fasthttp.QueryArgs().VisitAll(func(key []byte, val []byte) {
data[getString(key)] = append(data[getString(key)], getString(val)) data[getString(key)] = append(data[getString(key)], getString(val))
@ -642,7 +642,7 @@ func (ctx *Ctx) Next(err ...error) {
// OriginalURL contains the original request URL. // OriginalURL contains the original request URL.
// Returned value is only valid within the handler. Do not store any references. // Returned value is only valid within the handler. Do not store any references.
// Make copies or use the Immutable setting instead. // Make copies or use the Immutable setting to use the value outside the Handler.
func (ctx *Ctx) OriginalURL() string { func (ctx *Ctx) OriginalURL() string {
return getString(ctx.Fasthttp.Request.Header.RequestURI()) return getString(ctx.Fasthttp.Request.Header.RequestURI())
} }

View File

@ -1536,6 +1536,7 @@ func Benchmark_Ctx_SendBytes_B(b *testing.B) {
utils.AssertEqual(b, []byte("Hello, world!"), c.Fasthttp.Response.Body()) utils.AssertEqual(b, []byte("Hello, world!"), c.Fasthttp.Response.Body())
} }
// go test -run Benchmark_Ctx_QueryParser
func Test_Ctx_QueryParser(t *testing.T) { func Test_Ctx_QueryParser(t *testing.T) {
t.Parallel() t.Parallel()
app := New() app := New()
@ -1554,6 +1555,7 @@ func Test_Ctx_QueryParser(t *testing.T) {
utils.AssertEqual(t, 2, len(q.Hobby)) utils.AssertEqual(t, 2, len(q.Hobby))
} }
// go test -v -run=^$ -bench=Benchmark_Ctx_QueryParser -benchmem -count=4
func Benchmark_Ctx_QueryParser(b *testing.B) { func Benchmark_Ctx_QueryParser(b *testing.B) {
app := New() app := New()
ctx := app.AcquireCtx(&fasthttp.RequestCtx{}) ctx := app.AcquireCtx(&fasthttp.RequestCtx{})

View File

@ -60,14 +60,17 @@ func (app *App) prefork(addr string, tlsconfig ...*tls.Config) (err error) {
_ = proc.Process.Kill() _ = proc.Process.Kill()
} }
}() }()
// collect child pids // collect child pids
pids := []string{} pids := []string{}
// launch child procs // launch child procs
for i := 0; i < max; i++ { for i := 0; i < max; i++ {
/* #nosec G204 */ /* #nosec G204 */
cmd := exec.Command(os.Args[0], os.Args[1:]...) cmd := exec.Command(os.Args[0], os.Args[1:]...)
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr
// add fiber prefork child flag into child proc env // add fiber prefork child flag into child proc env
cmd.Env = append(os.Environ(), cmd.Env = append(os.Environ(),
fmt.Sprintf("%s=%s", envPreforkChildKey, envPreforkChildVal), fmt.Sprintf("%s=%s", envPreforkChildKey, envPreforkChildVal),
@ -75,9 +78,11 @@ func (app *App) prefork(addr string, tlsconfig ...*tls.Config) (err error) {
if err = cmd.Start(); err != nil { if err = cmd.Start(); err != nil {
return fmt.Errorf("failed to start a child prefork process, error: %v", err) return fmt.Errorf("failed to start a child prefork process, error: %v", err)
} }
// store child process // store child process
childs[cmd.Process.Pid] = cmd childs[cmd.Process.Pid] = cmd
pids = append(pids, strconv.Itoa(cmd.Process.Pid)) pids = append(pids, strconv.Itoa(cmd.Process.Pid))
// notify master if child crashes // notify master if child crashes
go func() { go func() {
channel <- child{cmd.Process.Pid, cmd.Wait()} channel <- child{cmd.Process.Pid, cmd.Wait()}