func RestoreStationsTable(input *db.RecordReader, output *db.StationDB) error { for { rec, err := input.ReadRecord() if err == io.EOF { break } else if err != nil { log.Printf("Error reading record: %s", err.Error()) return err } s := &pb.Station{} err = proto.Unmarshal(rec, s) if err != nil { log.Printf("Error parsing record: %s", err.Error()) return err } err = output.Store(s) if err != nil { log.Printf("Error writing record: %s", err.Error()) return err } fmt.Printf(".") } fmt.Printf("\n") log.Printf("Stations table restored.") return nil }
func addStationHandler(sdb *db.StationDB, w http.ResponseWriter, r *http.Request, user userView) { station, err := db.NewStation(user.Id) if err != nil { log.Printf("Station DB NewStation error: %s", err.Error()) http.Error(w, "", http.StatusInternalServerError) return } if err = sdb.Store(station); err != nil { log.Printf("Station DB Store error: %s", err.Error()) http.Error(w, "", http.StatusInternalServerError) return } redirect := stationUrl("/station/edit", *station.Id) http.Redirect(w, r, redirect, http.StatusFound) }
func editStationPOST(sdb *db.StationDB, s *pb.Station, w http.ResponseWriter, r *http.Request, user userView) { if err := r.ParseForm(); err != nil { http.Error(w, err.Error(), http.StatusBadRequest) return } log.Print(r.Form) s.Name = proto.String(r.Form.Get("name")) s.Notes = proto.String(r.Form.Get("notes")) setOptionalFloat(r.Form.Get("latitude"), &s.Lat) setOptionalFloat(r.Form.Get("longitude"), &s.Lng) setOptionalFloat(r.Form.Get("elevation"), &s.Elevation) if r.Form["has_vhf"] == nil { s.Capabilities.VhfLimits = nil } else { vhf := &pb.AzElLimits{} s.Capabilities.VhfLimits = vhf setOptionalFloat(r.Form.Get("vhf_min_azimuth"), &vhf.MinAzimuthDegrees) setOptionalFloat(r.Form.Get("vhf_max_azimuth"), &vhf.MaxAzimuthDegrees) setOptionalFloat(r.Form.Get("vhf_min_elevation"), &vhf.MinElevationDegrees) setOptionalFloat(r.Form.Get("vhf_max_elevation"), &vhf.MaxElevationDegrees) } if r.Form["has_uhf"] == nil { s.Capabilities.UhfLimits = nil } else { uhf := &pb.AzElLimits{} s.Capabilities.UhfLimits = uhf setOptionalFloat(r.Form.Get("uhf_min_azimuth"), &uhf.MinAzimuthDegrees) setOptionalFloat(r.Form.Get("uhf_max_azimuth"), &uhf.MaxAzimuthDegrees) setOptionalFloat(r.Form.Get("uhf_min_elevation"), &uhf.MinElevationDegrees) setOptionalFloat(r.Form.Get("uhf_max_elevation"), &uhf.MaxElevationDegrees) } if r.Form["scheduler_enabled"] == nil { s.SchedulerEnabled = nil } else { s.SchedulerEnabled = proto.Bool(true) } err := sdb.Store(s) if err != nil { log.Printf("Station DB store error: %s", err.Error()) http.Error(w, "", http.StatusInternalServerError) return } redirect := stationUrl("/station", *s.Id) http.Redirect(w, r, redirect, http.StatusFound) }