mirror of https://github.com/gofiber/fiber.git
Merge pull request #471 from ReneWerner87/master
🐛 flag.Parse not working when using Prefork on Fiber #469pull/472/head
commit
f20e66efee
21
app.go
21
app.go
|
@ -7,6 +7,7 @@ package fiber
|
|||
import (
|
||||
"bufio"
|
||||
"crypto/tls"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
|
@ -203,6 +204,18 @@ var (
|
|||
defaultCompressedFileSuffix = ".fiber.gz"
|
||||
)
|
||||
|
||||
var (
|
||||
preforkFlag, childFlag = "-prefork", "-child"
|
||||
prefork, child bool
|
||||
)
|
||||
|
||||
func init() { //nolint:gochecknoinits
|
||||
// Definition flag to not break the program when the user adds their own flags
|
||||
// and runs `flag.Parse()`
|
||||
flag.BoolVar(&prefork, childFlag[1:], false, "Is a child process")
|
||||
flag.BoolVar(&child, preforkFlag[1:], false, "use prefork")
|
||||
}
|
||||
|
||||
// New creates a new Fiber named instance.
|
||||
// You can pass optional settings when creating a new instance.
|
||||
func New(settings ...*Settings) *App {
|
||||
|
@ -247,7 +260,7 @@ func New(settings ...*Settings) *App {
|
|||
}
|
||||
|
||||
if !app.Settings.Prefork { // Default to -prefork flag if false
|
||||
app.Settings.Prefork = utils.GetArgument("-prefork")
|
||||
app.Settings.Prefork = utils.GetArgument(preforkFlag)
|
||||
}
|
||||
// Replace unsafe conversion functions
|
||||
if app.Settings.Immutable {
|
||||
|
@ -407,7 +420,7 @@ func (app *App) Listen(address interface{}, tlsconfig ...*tls.Config) error {
|
|||
ln = tls.NewListener(ln, tlsconfig[0])
|
||||
}
|
||||
// Print startup message
|
||||
if !app.Settings.DisableStartupMessage && !utils.GetArgument("-child") {
|
||||
if !app.Settings.DisableStartupMessage && !utils.GetArgument(childFlag) {
|
||||
startupMessage(ln)
|
||||
}
|
||||
|
||||
|
@ -526,7 +539,7 @@ func (app *App) Routes() []*Route {
|
|||
// Sharding: https://www.nginx.com/blog/socket-sharding-nginx-release-1-9-1/
|
||||
func (app *App) prefork(address string) (ln net.Listener, err error) {
|
||||
// Master proc
|
||||
if !utils.GetArgument("-child") {
|
||||
if !utils.GetArgument(childFlag) {
|
||||
addr, err := net.ResolveTCPAddr("tcp", address)
|
||||
if err != nil {
|
||||
return ln, err
|
||||
|
@ -543,7 +556,7 @@ func (app *App) prefork(address string) (ln net.Listener, err error) {
|
|||
childs := make([]*exec.Cmd, runtime.NumCPU()/2)
|
||||
// #nosec G204
|
||||
for i := range childs {
|
||||
childs[i] = exec.Command(os.Args[0], append(os.Args[1:], "-prefork", "-child")...)
|
||||
childs[i] = exec.Command(os.Args[0], append(os.Args[1:], preforkFlag, childFlag)...)
|
||||
childs[i].Stdout = os.Stdout
|
||||
childs[i].Stderr = os.Stderr
|
||||
childs[i].ExtraFiles = files
|
||||
|
|
Loading…
Reference in New Issue