11 const PARAM_IDS = "ids"
14 // ============================================================================
15 func handler(w http.ResponseWriter, r *http.Request) {
18 fmt.Fprintln(w, "ERROR!", err)
22 action := r.URL.Path[1:]
30 fmt.Fprintf(w, "Unrecognized request: %s\n", r.URL.Path[1:])
31 fmt.Fprintf(w, "id: %s\n", r.FormValue("id"))
33 fmt.Fprintln(w, "URL: ", r.URL)
34 fmt.Fprintln(w, "Query: ", r.URL.Query())
38 func handleInfo(w http.ResponseWriter, r *http.Request) {
39 idParams := r.Form[PARAM_IDS]
40 if 1 != len(idParams) {
41 fmt.Fprintln(w, "ERROR! Detected either zero or multiple ids= parameters. Exactly one expected.")
45 idParam := idParams[0]
46 idStrings := strings.Split(idParam, ",")
47 ids := make([]int, len(idStrings))
48 for i, v := range(idStrings) {
50 ids[i], err = strconv.Atoi(v)
56 books := queryBooksByIds(ids)
60 jsonValue, err = json.Marshal(books)
62 fmt.Fprintln(w, "ERROR!", err)
68 func handleSearch(w http.ResponseWriter, r *http.Request) {
69 fields := []Field{Author, Title, Series}
71 terms := make([]SearchTerm, len(fields))
74 for _, fv := range(fields) {
75 paramName := fv.String()
76 paramValues := r.Form[paramName]
77 for _, pv := range(paramValues) {
78 if count >= len(terms) {
79 fmt.Printf("WARNING: limit of %v search terms exceeded. One or more terms ignored.")
82 terms[count] = SearchTerm{Attribute:fv, Text:pv}
89 ids := queryIds(terms)
91 jsonValue, err := json.Marshal(ids)
93 fmt.Fprintln(w, "ERROR!", err)