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

Method register

router.go:636–712  ·  view source on GitHub ↗
(methods []string, pathRaw string, group *Group, handlers ...Handler)

Source from the content-addressed store, hash-verified

634}
635
636func (app *App) register(methods []string, pathRaw string, group *Group, handlers ...Handler) {
637 // A regular route requires at least one ctx handler
638 if len(handlers) == 0 && group == nil {
639 panic(fmt.Sprintf("missing handler/middleware in route: %s\n", pathRaw))
640 }
641 // No nil handlers allowed
642 for _, h := range handlers {
643 if h == nil {
644 panic(fmt.Sprintf("nil handler in route: %s\n", pathRaw))
645 }
646 }
647
648 // Precompute path normalization ONCE
649 if pathRaw == "" {
650 pathRaw = "/"
651 }
652 if pathRaw[0] != '/' {
653 pathRaw = "/" + pathRaw
654 }
655 pathPretty := pathRaw
656 if !app.config.CaseSensitive {
657 pathPretty = utilsstrings.ToLower(pathPretty)
658 }
659 if !app.config.StrictRouting && len(pathPretty) > 1 {
660 pathPretty = utils.TrimRight(pathPretty, '/')
661 }
662 pathClean := RemoveEscapeChar(pathPretty)
663
664 parsedRaw := parseRoute(pathRaw, app.config.RegexHandler, app.customConstraints...)
665 parsedPretty := parseRoute(pathPretty, app.config.RegexHandler, app.customConstraints...)
666
667 isMount := group != nil && group.app != app
668
669 for _, method := range methods {
670 method = utilsstrings.ToUpper(method)
671 if method != methodUse && app.methodInt(method) == -1 {
672 panic(fmt.Sprintf("add: invalid http method %s\n", method))
673 }
674
675 isUse := method == methodUse
676 isStar := pathClean == "/*"
677 isRoot := pathClean == "/"
678
679 route := Route{
680 use: isUse,
681 mount: isMount,
682 star: isStar,
683 root: isRoot,
684 caseSensitive: app.config.CaseSensitive,
685
686 path: pathClean,
687 routeParser: parsedPretty,
688 Params: parsedRaw.params,
689 group: group,
690
691 Path: pathRaw,
692 Method: method,
693 Handlers: handlers,

Callers 15

mountMethod · 0.95
UseMethod · 0.95
AddMethod · 0.95
GroupMethod · 0.95
mountMethod · 0.80
AllMethod · 0.80
AddMethod · 0.80
UseMethod · 0.80
AddMethod · 0.80
GroupMethod · 0.80

Calls 4

methodIntMethod · 0.95
addRouteMethod · 0.95
RemoveEscapeCharFunction · 0.85
parseRouteFunction · 0.85