func (h *Handlers) AllPeopleHandler(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) groupname := vars["group"] p := GetPeopleData(groupname) myjson, _ := json.Marshal(p) w.Write([]byte(myjson)) }
func (h *Handlers) PersonHandler(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) person_id, _ := strconv.ParseInt(vars["id"], 10, 64) p, err := GetPersonData(person_id) if err != nil { // return some 404 status to the app fmt.Println(err) w.WriteHeader(404) return } myjson, _ := json.Marshal(p) w.Write([]byte(myjson)) }
func (h *Handlers) PersonPutHandler(w http.ResponseWriter, r *http.Request) { var p Person vars := mux.Vars(r) person_id, _ := strconv.ParseInt(vars["id"], 10, 64) p.Id = person_id body, err := ioutil.ReadAll(r.Body) if err != nil { fmt.Println(err) } err = json.Unmarshal(body, &p) if err != nil { fmt.Println(err) } UpdatePerson(p) }
func (h *Handlers) StaffRedirectHandler(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) username := vars["username"] url := fmt.Sprintf("%s/%s", Config.Staff.DirectoryUrl, username) http.Redirect(w, r, url, http.StatusFound) }