package ajax import ( "local/storage" "local/todo-server/config" "net/http" ) type Ajax struct { DB storage.DB } func New() (*Ajax, error) { db, err := storage.New(storage.TypeFromString(config.StoreType), config.StoreAddr, config.StoreUser, config.StorePass) return &Ajax{ DB: db, }, err } func (a *Ajax) HandleAjax(w http.ResponseWriter, r *http.Request) { params := r.URL.Query() var foo func(http.ResponseWriter, *http.Request) error if v := params.Get("loadLists"); v != "" { foo = a.loadLists } else if v := params.Get("loadTasks"); v != "" { foo = a.loadTasks } else if v := params.Get("newTask"); v != "" { foo = a.newTask } else if v := params.Get("fullNewTask"); v != "" { foo = a.newTask } else if v := params.Get("deleteTask"); v != "" { foo = a.deleteTask } else if v := params.Get("completeTask"); v != "" { foo = a.completeTask } else if v := params.Get("editNote"); v != "" { foo = a.editNote } else if v := params.Get("editTask"); v != "" { foo = a.editTask } else if v := params.Get("changeOrder"); v != "" { foo = a.changeOrder } else if v := params.Get("suggestTags"); v != "" { foo = a.suggestTags } else if v := params.Get("setPrio"); v != "" { foo = a.setPrio } else if v := params.Get("tagCloud"); v != "" { foo = a.tagCloud } else if v := params.Get("addList"); v != "" { foo = a.addList } else if v := params.Get("renameList"); v != "" { foo = a.renameList } else if v := params.Get("deleteList"); v != "" { foo = a.deleteList } else if v := params.Get("setSort"); v != "" { foo = a.setSort } else if v := params.Get("publishList"); v != "" { foo = a.publishList } else if v := params.Get("moveTask"); v != "" { foo = a.moveTask } else if v := params.Get("changeListOrder"); v != "" { foo = a.changeListOrder } else if v := params.Get("parseTaskStr"); v != "" { foo = a.parseTaskStr } else if v := params.Get("clearCompletedInList"); v != "" { foo = a.clearCompletedInList } else if v := params.Get("setShowNotesInList"); v != "" { foo = a.setShowNotesInList } else if v := params.Get("setHideList"); v != "" { foo = a.setHideList } if err := foo(w, r); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } }