}
}
+/*
+func handleApp(w http.ResponseWriter, r *http.Request) {
+ fmt.Println("handleApp():", r.URL.Path)
+
+ // Security check: prevent walking up the directory
+ pos := strings.Index(r.Url.Path, "../")
+ if (-1) == pos {
+ fmt.Fprintln(w, "Paths containing \"../\" are not permitted:", r.URL.Path)
+ return
+ }
+
+ fileName := "../app" + r.URL.Path
+ _, err := os.Stat(fileName)
+ if nil != err {
+ fmt.Fprintln(w, "Failed to find file:", fileName, err)
+ return
+ }
+
+ http.ServeFile(w, r, "../app/" + r.URL.Path[1:])
+}
+*/
+
func handleDownload(w http.ResponseWriter, r *http.Request) {
path := r.URL.Path[1:]
tok := strings.Split(path, "/")
idParam := idParams[0]
idStrings := strings.Split(idParam, ",")
ids := make([]int, len(idStrings))
+ var err error
for i, v := range(idStrings) {
- var err error
ids[i], err = strconv.Atoi(v)
if nil != err {
ids[i] = 0
books := queryBooksByIds(ids)
var jsonValue []byte
- var err error
jsonValue, err = json.Marshal(books)
if nil != err {
fmt.Fprintln(w, "ERROR!", err)
}
func handleSearch(w http.ResponseWriter, r *http.Request) {
+ var err error
+ fmt.Println("DEBUG: handleSearch(): " + r.URL.Path)
+
fields := []Field{Author, Title, Series}
terms := make([]SearchTerm, len(fields))
paramName := fv.String()
paramValues := r.Form[paramName]
for _, pv := range(paramValues) {
+ fmt.Println("DEBUG: handleSearch(): ", paramName, "=", pv)
if count >= len(terms) {
- fmt.Printf("WARNING: limit of %v search terms exceeded. One or more terms ignored.")
+ fmt.Printf("WARNING: limit of %d search terms exceeded. One or more terms ignored.", len(terms))
break
}
terms[count] = SearchTerm{Attribute:fv, Text:pv}
w.Write(jsonValue)
}
}
+