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)
| 664 | // ServerHeader: "Fiber", |
| 665 | // }) |
| 666 | func 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 | } |