Merge pull request #717 from Fenny/master

⚙ init on Handler call
pull/720/head
Fenny 2020-08-11 00:12:24 +02:00 committed by GitHub
commit bfbb0273e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 3 deletions

9
app.go
View File

@ -439,7 +439,7 @@ func (app *App) Serve(ln net.Listener, tlsconfig ...*tls.Config) error {
// This method does not support the Prefork feature // This method does not support the Prefork feature
// To use Prefork, please use app.Listen() // To use Prefork, please use app.Listen()
func (app *App) Listener(ln net.Listener, tlsconfig ...*tls.Config) error { func (app *App) Listener(ln net.Listener, tlsconfig ...*tls.Config) error {
// Update fiber server settings // Update server settings
app.init() app.init()
// TLS config // TLS config
if len(tlsconfig) > 0 { if len(tlsconfig) > 0 {
@ -472,7 +472,7 @@ func (app *App) Listen(address interface{}, tlsconfig ...*tls.Config) error {
if !strings.Contains(addr, ":") { if !strings.Contains(addr, ":") {
addr = ":" + addr addr = ":" + addr
} }
// Update fiber server settings // Update server settings
app.init() app.init()
// Start prefork // Start prefork
if app.Settings.Prefork { if app.Settings.Prefork {
@ -502,6 +502,7 @@ func (app *App) Listen(address interface{}, tlsconfig ...*tls.Config) error {
// Handler returns the server handler. // Handler returns the server handler.
func (app *App) Handler() fasthttp.RequestHandler { func (app *App) Handler() fasthttp.RequestHandler {
app.init()
return app.handler return app.handler
} }
@ -589,7 +590,10 @@ func (dl *disableLogger) Printf(format string, args ...interface{}) {
} }
func (app *App) init() *App { func (app *App) init() *App {
// Lock application
app.mutex.Lock() app.mutex.Lock()
defer app.mutex.Unlock()
// Load view engine if provided // Load view engine if provided
if app.Settings != nil { if app.Settings != nil {
// Only load templates if an view engine is specified // Only load templates if an view engine is specified
@ -636,7 +640,6 @@ func (app *App) init() *App {
app.server.ReadBufferSize = app.Settings.ReadBufferSize app.server.ReadBufferSize = app.Settings.ReadBufferSize
app.server.WriteBufferSize = app.Settings.WriteBufferSize app.server.WriteBufferSize = app.Settings.WriteBufferSize
app.buildTree() app.buildTree()
app.mutex.Unlock()
return app return app
} }