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

Method Params

req.go:856–878  ·  view source on GitHub ↗

Params is used to get the route parameters. Defaults to empty string "" if the param doesn't exist. If a default value is given, it will return that value if the param doesn't exist. Returned value is only valid within the handler. Do not store any references. Make copies or use the Immutable settin

(key string, defaultValue ...string)

Source from the content-addressed store, hash-verified

854// Returned value is only valid within the handler. Do not store any references.
855// Make copies or use the Immutable setting to use the value outside the Handler.
856func (r *DefaultReq) Params(key string, defaultValue ...string) string {
857 if key == "*" || key == "+" {
858 key += "1"
859 }
860
861 app := r.c.app
862 route := r.c.Route()
863 values := &r.c.values
864 for i := range route.Params {
865 if len(key) != len(route.Params[i]) {
866 continue
867 }
868 if route.Params[i] == key || (!app.config.CaseSensitive && utils.EqualFold(route.Params[i], key)) {
869 // if there is no value for the key
870 if len(values) <= i || values[i] == "" {
871 break
872 }
873 val := values[i]
874 return r.c.app.GetString(val)
875 }
876 }
877 return defaultString("", defaultValue)
878}
879
880// Params is used to get the route parameters.
881// This function is generic and can handle different route parameters type values.

Callers

nothing calls this directly

Calls 3

defaultStringFunction · 0.85
RouteMethod · 0.65
GetStringMethod · 0.45

Tested by

no test coverage detected