Home / File/ adapter.go — fiber Source File

adapter.go — fiber Source File

Architecture documentation for adapter.go, a go file in the fiber codebase. 1 imports, 0 dependents.

File go FiberCore Adapters 1 imports 8 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  be85d8ad_2478_47b5_e5e7_f666d58bdb3a["adapter.go"]
  adf3d4e8_4d86_86c1_e6cc_281d7b4104af["fmt"]
  be85d8ad_2478_47b5_e5e7_f666d58bdb3a --> adf3d4e8_4d86_86c1_e6cc_281d7b4104af
  style be85d8ad_2478_47b5_e5e7_f666d58bdb3a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

package fiber

import (
	"fmt"
	"net/http"
	"reflect"

	"github.com/valyala/fasthttp"
	"github.com/valyala/fasthttp/fasthttpadaptor"
)

// toFiberHandler converts a supported handler type to a Fiber handler.
func toFiberHandler(handler any) (Handler, bool) {
	if handler == nil {
		return nil, false
	}

	switch handler.(type) {
	case Handler, func(Ctx): // (1)-(2) Fiber handlers
		return adaptFiberHandler(handler)
	case func(Req, Res) error, func(Req, Res), func(Req, Res, func() error) error, func(Req, Res, func() error), func(Req, Res, func()) error, func(Req, Res, func()), func(Req, Res, func(error)), func(Req, Res, func(error)) error, func(Req, Res, func(error) error), func(Req, Res, func(error) error) error: // (3)-(12) Express-style request handlers
		return adaptExpressHandler(handler)
	case http.HandlerFunc, http.Handler, func(http.ResponseWriter, *http.Request): // (13)-(15) net/http handlers
		return adaptHTTPHandler(handler)
	case fasthttp.RequestHandler, func(*fasthttp.RequestCtx) error: // (16)-(17) fasthttp handlers
		return adaptFastHTTPHandler(handler)
	default: // (18) unsupported handler type
		return nil, false
	}
}

func adaptFiberHandler(handler any) (Handler, bool) {
	switch h := handler.(type) {
	case Handler: // (1) direct Fiber handler
		if h == nil {
			return nil, false
		}
		return h, true
	case func(Ctx): // (2) Fiber handler without error return
		if h == nil {
			return nil, false
		}
		return func(c Ctx) error {
			h(c)
			return nil
		}, true
	default:
		return nil, false
	}
}

func adaptExpressHandler(handler any) (Handler, bool) {
	switch h := handler.(type) {
	case func(Req, Res) error: // (3) Express-style handler with error return
		if h == nil {
			return nil, false
		}
		return func(c Ctx) error {
			return h(c.Req(), c.Res())
		}, true
// ... (216 more lines)

Domain

Subdomains

Classes

Dependencies

  • fmt

Frequently Asked Questions

What does adapter.go do?
adapter.go is a source file in the fiber codebase, written in go. It belongs to the FiberCore domain, Adapters subdomain.
What functions are defined in adapter.go?
adapter.go defines 8 function(s): adaptExpressHandler, adaptFastHTTPHandler, adaptFiberHandler, adaptHTTPHandler, collectHandlers, isNilableKind, toFiberHandler, wrapHTTPHandler.
What does adapter.go depend on?
adapter.go imports 1 module(s): fmt.
Where is adapter.go in the architecture?
adapter.go is located at adapter.go (domain: FiberCore, subdomain: Adapters).

Analyze Your Own Codebase

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

Try Supermodel Free