func HandleServerUpdate(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) if !bson.IsObjectIdHex(vars["id"]) { http.Error(w, "Not Found", http.StatusNotFound) return } srv, err := data.GetServer(bson.ObjectIdHex(vars["id"])) if err != nil { panic(err) } err = r.ParseForm() if err != nil { http.Error(w, "Bad Request", http.StatusBadRequest) return } body := struct { Label string `schema:"label"` Settings struct { Address string `schema:"address"` Weight int `schema:"weight"` Availability string `schema:"availability"` } `schema:"settings"` }{} err = schema.NewDecoder().Decode(&body, r.PostForm) if err != nil { http.Error(w, "Bad Request", http.StatusBadRequest) return } srv.Label = body.Label srv.Settings.Address = body.Settings.Address srv.Settings.Weight = body.Settings.Weight srv.Settings.Availability = data.Availability(body.Settings.Availability) err = srv.Put() if err != nil { panic(err) } bal, err := srv.Balancer() if err != nil { panic(err) } err = feline.Commit(bal) if err != nil { panic(err) } http.Redirect(w, r, "/balancers/"+srv.BalancerId.Hex(), http.StatusSeeOther) }
func ServeServer(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) if !bson.IsObjectIdHex(vars["id"]) { http.Error(w, "Not Found", http.StatusNotFound) return } srv, err := data.GetServer(bson.ObjectIdHex(vars["id"])) if err != nil { panic(err) } // err = TplServerView.Execute(w, struct { // Server *data.Server // }{ // Server: srv, // }) // if err != nil { // panic(err) // } http.Redirect(w, r, "/servers/"+srv.Id.Hex()+"/edit", http.StatusSeeOther) }
func ServeServerEditForm(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) if !bson.IsObjectIdHex(vars["id"]) { http.Error(w, "Not Found", http.StatusNotFound) return } srv, err := data.GetServer(bson.ObjectIdHex(vars["id"])) if err != nil { panic(err) } err = TplServerEditForm.Execute(w, struct { Server *data.Server Availabilities []data.Availability }{ Server: srv, Availabilities: data.Availabilities, }) if err != nil { panic(err) } }