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

Method Route

redirect.go:342–376  ·  view source on GitHub ↗

Route redirects to the Route registered in the app with appropriate parameters. If you want to send queries or params to route, you should use config parameter.

(name string, config ...RedirectConfig)

Source from the content-addressed store, hash-verified

340// Route redirects to the Route registered in the app with appropriate parameters.
341// If you want to send queries or params to route, you should use config parameter.
342func (r *Redirect) Route(name string, config ...RedirectConfig) error {
343 // Check config
344 cfg := RedirectConfig{}
345 if len(config) > 0 {
346 cfg = config[0]
347 }
348
349 // Get location from route name
350 route := r.c.App().GetRoute(name)
351 location, err := r.c.getLocationFromRoute(&route, cfg.Params)
352 if err != nil {
353 return err
354 }
355
356 // Check queries
357 if len(cfg.Queries) > 0 {
358 queryText := bytebufferpool.Get()
359 defer bytebufferpool.Put(queryText)
360
361 first := true
362 for k, v := range cfg.Queries {
363 if !first {
364 queryText.WriteByte('&')
365 }
366 first = false
367 queryText.WriteString(k)
368 queryText.WriteByte('=')
369 queryText.WriteString(v)
370 }
371
372 return r.To(location + "?" + r.c.app.toString(queryText.Bytes()))
373 }
374
375 return r.To(location)
376}
377
378// Back redirect to the URL to referer.
379// It validates that the Referer is same-origin to prevent open redirect attacks.

Callers

nothing calls this directly

Calls 10

ToMethod · 0.95
GetRouteMethod · 0.80
toStringMethod · 0.80
AppMethod · 0.65
getLocationFromRouteMethod · 0.65
GetMethod · 0.65
PutMethod · 0.65
WriteByteMethod · 0.65
WriteStringMethod · 0.65
BytesMethod · 0.65

Tested by

no test coverage detected