Code cleanup + documentation

This commit is contained in:
Manu Mtz-Almeida
2015-05-28 03:22:34 +02:00
parent 5680762712
commit e899d8a99e
3 changed files with 63 additions and 52 deletions
+27
View File
@@ -9,6 +9,33 @@ import (
"unicode"
)
// 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 router.
// 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
// 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) Get(name string) (string, bool) {
for _, entry := range ps {
if entry.Key == name {
return entry.Value, true
}
}
return "", false
}
func (ps Params) ByName(name string) (va string) {
va, _ = ps.Get(name)
return
}
func min(a, b int) int {
if a <= b {
return a