summaryrefslogtreecommitdiffstats
path: root/search
diff options
context:
space:
mode:
Diffstat (limited to 'search')
-rw-r--r--search/search.go17
1 files changed, 11 insertions, 6 deletions
diff --git a/search/search.go b/search/search.go
index 1b297c3..7e0d6e0 100644
--- a/search/search.go
+++ b/search/search.go
@@ -19,21 +19,26 @@ type Search struct {
Location string
Message string
MatchingCoords []photon.Coordinates
+ Enabled bool
}
-func NewSearch(r *http.Request) (*Search, error) {
+func NewSearch(r *http.Request) (*Search, error, int) {
s := new(Search)
s.Title = "search"
s.Version = version.Version
+ s.Enabled = photon.Enabled()
+ if !s.Enabled {
+ return s, fmt.Errorf("search disabled"), 404
+ }
if r.Method == "GET" {
- return s, nil
+ return s, nil, 200
}
// Get location.
err := r.ParseForm()
if err != nil {
- return s, fmt.Errorf("form: %v", err)
+ return s, fmt.Errorf("form: %v", err), 500
}
location := strings.TrimSpace(r.PostForm.Get("location"))
s.Location = location
@@ -46,11 +51,11 @@ func NewSearch(r *http.Request) (*Search, error) {
if err != nil {
log.Printf("search: geocode: %v", err)
s.Message = "unable to lookup location"
- return s, nil
+ return s, nil, 200
}
if len(s.MatchingCoords) < 1 {
s.Message = "location not found"
- return s, nil
+ return s, nil, 200
}
- return s, nil
+ return s, nil, 200
}