-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathparam.go
More file actions
32 lines (26 loc) · 905 Bytes
/
param.go
File metadata and controls
32 lines (26 loc) · 905 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package httpdispatch
// Param is a single URL parameter, consisting of a key and a value.
type Param struct {
Key string
Value string
}
// Params is a Param-slice, as returned by the dispatcher.
// The slice is ordered, the first URL parameter is also the first slice value.
// It is therefore safe to read values by the index.
type Params []Param
// DefName returns the value and true of the first Param which key matches the given name.
// If no matching Param is found, an empty string and false is returned.
func (ps Params) DefName(name string) (string, bool) {
for _, p := range ps {
if p.Key == name {
return p.Value, true
}
}
return "", false
}
// ByName returns the value of the first Param which key matches the given name.
// If no matching Param is found, an empty string is returned.
func (ps Params) ByName(name string) string {
val, _ := ps.DefName(name)
return val
}