-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathcountries.go
More file actions
29 lines (24 loc) · 652 Bytes
/
Copy pathcountries.go
File metadata and controls
29 lines (24 loc) · 652 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
package main
import (
"sort"
"github.com/jirenius/go-res"
)
// Countries is a sorted list of country names.
var Countries = sort.StringSlice{
"France",
"Germany",
"Sweden",
"United Kingdom",
}
// CountriesContains searches for a country and returns true if it is found in
// Countries.
func CountriesContains(country string) bool {
i := sort.SearchStrings(Countries, country)
return i != len(Countries) && Countries[i] == country
}
// CountriesHandler is a handler that serves the static Countries collection.
var CountriesHandler = res.OptionFunc(func(rh *res.Handler) {
rh.Get = func(r res.GetRequest) {
r.Collection(Countries)
}
})