Initial scaffold for search
parent
7b5aeeb87e
commit
70f92f299e
12
app.go
12
app.go
|
@ -53,8 +53,8 @@ type appRequest struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type appSearch struct {
|
type appSearch struct {
|
||||||
App Datetime
|
App Datetime
|
||||||
Req map[string]string
|
Search []*data.City
|
||||||
}
|
}
|
||||||
|
|
||||||
// index handles all incoming page requests
|
// index handles all incoming page requests
|
||||||
|
@ -111,8 +111,12 @@ func (app Datetime) search(w http.ResponseWriter, req *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: do search
|
// TODO: do search
|
||||||
search := map[string]string{
|
query := req.URL.Query()
|
||||||
"hi": "hello",
|
search, err := FullSearchCities(app.cities, query.Get("zone"))
|
||||||
|
if err != nil {
|
||||||
|
l.Error("search failed", zap.Error(err))
|
||||||
|
app.error(HTTPError{http.StatusInternalServerError, err}, w, req)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l.Debug("rendering template", zap.Reflect("search", search))
|
l.Debug("rendering template", zap.Reflect("search", search))
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/serverwentdown/datetime.link/data"
|
||||||
|
)
|
||||||
|
|
||||||
|
// FullSearchCities uses a very basic iterative method to search for a city
|
||||||
|
// with the given string
|
||||||
|
func FullSearchCities(cities map[string]*data.City, zone string) ([]*data.City, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
11
template.go
11
template.go
|
@ -19,13 +19,20 @@ func (app Datetime) loadTemplate(name string, w http.ResponseWriter, req *http.R
|
||||||
accept := req.Header.Get("Accept")
|
accept := req.Header.Get("Accept")
|
||||||
tmpl, contentType, acceptable := app.chooseTemplate(accept, name)
|
tmpl, contentType, acceptable := app.chooseTemplate(accept, name)
|
||||||
if !acceptable {
|
if !acceptable {
|
||||||
app.simpleError(HTTPError{http.StatusNotAcceptable, nil}, w, req)
|
if name == "error" {
|
||||||
|
app.simpleError(HTTPError{http.StatusNotAcceptable, nil}, w, req)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
app.error(HTTPError{http.StatusNotAcceptable, nil}, w, req)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if tmpl == nil {
|
if tmpl == nil {
|
||||||
err := fmt.Errorf("%w \"%s\" for \"%s\"", ErrTemplateNotFound, name, accept)
|
err := fmt.Errorf("%w \"%s\" for \"%s\"", ErrTemplateNotFound, name, accept)
|
||||||
l.Warn("unable to find template", zap.Error(err), zap.String("name", name), zap.String("accept", accept))
|
l.Warn("unable to find template", zap.Error(err), zap.String("name", name), zap.String("accept", accept))
|
||||||
app.simpleError(HTTPError{http.StatusNotAcceptable, err}, w, req)
|
if name == "error" {
|
||||||
|
app.simpleError(HTTPError{http.StatusNotAcceptable, err}, w, req)
|
||||||
|
}
|
||||||
|
app.error(HTTPError{http.StatusNotAcceptable, err}, w, req)
|
||||||
//app.simpleError(HTTPError{http.StatusInternalServerError, ErrNoTemplate}, w, req)
|
//app.simpleError(HTTPError{http.StatusInternalServerError, ErrNoTemplate}, w, req)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{{.Req | jsonMarshal | thisIsSafe }}
|
{{.Search | jsonMarshal | thisIsSafe }}
|
||||||
|
|
Loading…
Reference in New Issue