mirror of
https://github.com/sot-tech/mochi.git
synced 2026-04-26 15:40:01 -07:00
Merge pull request #466 from elotreum/routeparam-enhancement
add helper method to retrieve RouteParam by name
This commit is contained in:
@@ -70,6 +70,21 @@ type RouteParam struct {
|
||||
// RouteParams is a collection of RouteParam instances.
|
||||
type RouteParams []RouteParam
|
||||
|
||||
// ByName returns the value of the first RouteParam that matches the given
|
||||
// name. If no matching RouteParam is found, an empty string is returned.
|
||||
// In the event that a "catch-all" parameter is provided on the route and
|
||||
// no value is matched, an empty string is returned. For example: a route of
|
||||
// "/announce/*param" matches on "/announce/". However, ByName("param") will
|
||||
// return an empty string.
|
||||
func (rp RouteParams) ByName(name string) string {
|
||||
for _, p := range rp {
|
||||
if p.Key == name {
|
||||
return p.Value
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// ParseURLData parses a request URL or UDP URLData as defined in BEP41.
|
||||
// It expects a concatenated string of the request's path and query parts as
|
||||
// defined in RFC 3986. As both the udp: and http: scheme used by BitTorrent
|
||||
|
||||
Reference in New Issue
Block a user