MCPcopy
hub / github.com/gofiber/fiber / New

Function New

app.go:666–788  ·  app.go::New

New creates a new Fiber named instance. app := fiber.New() You can pass optional configuration options by passing a Config struct: app := fiber.New(fiber.Config{ ServerHeader: "Fiber", })

(config ...Config)

Source from the content-addressed store, hash-verified

664// ServerHeader: "Fiber",
665// })
666func New(config ...Config) *App {
667 // Create a new app
668 app := &App{
669 // Create config
670 config: Config{},
671 toBytes: utils.UnsafeBytes,
672 toString: utils.UnsafeString,
673 latestRoute: &Route{},
674 customBinders: []CustomBinder{},
675 sendfiles: []*sendFileStore{},
676 }
677
678 // Create Ctx pool
679 app.pool = sync.Pool{
680 New: func() any {
681 if app.newCtxFunc != nil {
682 return app.newCtxFunc(app)
683 }
684 return NewDefaultCtx(app)
685 },
686 }
687
688 // Define hooks
689 app.hooks = newHooks(app)
690
691 // Define mountFields
692 app.mountFields = newMountFields(app)
693
694 // Define state
695 app.state = newState()
696
697 // Override config if provided
698 if len(config) > 0 {
699 app.config = config[0]
700 }
701
702 // Initialize configured before defaults are set
703 app.configured = app.config
704 if err := app.validateConfiguredServices(); err != nil {
705 panic(err)
706 }
707
708 // Override default values
709 if app.config.BodyLimit <= 0 {
710 app.config.BodyLimit = DefaultBodyLimit
711 }
712 if app.config.MaxRanges <= 0 {
713 app.config.MaxRanges = DefaultMaxRanges
714 }
715 if app.config.Concurrency <= 0 {
716 app.config.Concurrency = DefaultConcurrency
717 }
718 if app.config.ReadBufferSize <= 0 {
719 app.config.ReadBufferSize = DefaultReadBufferSize
720 }
721 if app.config.WriteBufferSize <= 0 {
722 app.config.WriteBufferSize = DefaultWriteBufferSize
723 }

Callers 15

Test_ListenFunction · 0.70
testGracefulShutdownFunction · 0.70
Test_Listen_PreforkFunction · 0.70
Test_Listen_TLSFunction · 0.70
Test_Listen_TLS_PreforkFunction · 0.70
Test_Listen_MutualTLSFunction · 0.70
Test_ListenerFunction · 0.70
Test_Listen_TLSConfigFunction · 0.70

Calls 10

handleTrustedProxyMethod · 0.95
initMethod · 0.95
NewDefaultCtxFunction · 0.85
newHooksFunction · 0.85
newMountFieldsFunction · 0.85
newStateFunction · 0.85
validateRegexHandlerFunction · 0.85
newSharedStateFunction · 0.85
defaultColorsFunction · 0.85

Tested by 15

Test_ListenFunction · 0.56
testGracefulShutdownFunction · 0.56
Test_Listen_PreforkFunction · 0.56
Test_Listen_TLSFunction · 0.56
Test_Listen_TLS_PreforkFunction · 0.56
Test_Listen_MutualTLSFunction · 0.56
Test_ListenerFunction · 0.56
Test_Listen_TLSConfigFunction · 0.56