Home / Function/ New() — fiber Function Reference

New() — fiber Function Reference

Architecture documentation for the New() function in app.go from the fiber codebase.

Entity Profile

Dependency Diagram

graph TD
  70b9fa45_2b4d_d5f2_f6d1_f44ce79d6061["New()"]
  258982c0_9752_bf98_01ce_836d4de563e1["app.go"]
  70b9fa45_2b4d_d5f2_f6d1_f44ce79d6061 -->|defined in| 258982c0_9752_bf98_01ce_836d4de563e1
  style 70b9fa45_2b4d_d5f2_f6d1_f44ce79d6061 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

app.go lines 529–648

func New(config ...Config) *App {
	// Create a new app
	app := &App{
		// Create config
		config:        Config{},
		toBytes:       utils.UnsafeBytes,
		toString:      utils.UnsafeString,
		latestRoute:   &Route{},
		customBinders: []CustomBinder{},
		sendfiles:     []*sendFileStore{},
	}

	// Create Ctx pool
	app.pool = sync.Pool{
		New: func() any {
			if app.newCtxFunc != nil {
				return app.newCtxFunc(app)
			}
			return NewDefaultCtx(app)
		},
	}

	// Define hooks
	app.hooks = newHooks(app)

	// Define mountFields
	app.mountFields = newMountFields(app)

	// Define state
	app.state = newState()

	// Override config if provided
	if len(config) > 0 {
		app.config = config[0]
	}

	// Initialize configured before defaults are set
	app.configured = app.config
	if err := app.validateConfiguredServices(); err != nil {
		panic(err)
	}

	// Override default values
	if app.config.BodyLimit <= 0 {
		app.config.BodyLimit = DefaultBodyLimit
	}
	if app.config.MaxRanges <= 0 {
		app.config.MaxRanges = DefaultMaxRanges
	}
	if app.config.Concurrency <= 0 {
		app.config.Concurrency = DefaultConcurrency
	}
	if app.config.ReadBufferSize <= 0 {
		app.config.ReadBufferSize = DefaultReadBufferSize
	}
	if app.config.WriteBufferSize <= 0 {
		app.config.WriteBufferSize = DefaultWriteBufferSize
	}
	if app.config.CompressedFileSuffixes == nil {
		app.config.CompressedFileSuffixes = map[string]string{
			"gzip": ".fiber.gz",
			"br":   ".fiber.br",
			"zstd": ".fiber.zst",
		}
	}

	if app.config.Immutable {
		app.toBytes, app.toString = toBytesImmutable, toStringImmutable
	}

	if app.config.ErrorHandler == nil {
		app.config.ErrorHandler = DefaultErrorHandler
	}

	if app.config.JSONEncoder == nil {
		app.config.JSONEncoder = json.Marshal
	}
	if app.config.JSONDecoder == nil {
		app.config.JSONDecoder = json.Unmarshal
	}
	if app.config.MsgPackEncoder == nil {

Domain

Subdomains

Defined In

Frequently Asked Questions

What does New() do?
New() is a function in the fiber codebase, defined in app.go.
Where is New() defined?
New() is defined in app.go at line 529.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free