示例#1
0
文件: fdb.go 项目: hugoh/complaints
func addtrackHandler(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	db := fdb.FlightDB{C: c}

	icaoId := r.FormValue("icaoid")
	callsign := strings.TrimSpace(r.FormValue("callsign"))
	tStr := r.FormValue("track")

	// Validate it works before persisting
	t := ftype.Track{}
	if err := t.Base64Decode(tStr); err != nil {
		c.Errorf(" /mdb/addtrack: decode failed: %v", err)
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}

	ftf := ftype.FrozenTrackFragment{
		TrackBase64: tStr,
		Callsign:    callsign,
		Icao24:      icaoId,
	}
	if err := db.AddTrackFrgament(ftf); err != nil {
		c.Errorf(" /mdb/addtrack: db.AddTrackFragment failed: %v", err)
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}

	// 3. Routine to merge track fragments ? Extra credit ?

	// c.Infof(" /mdb/addtrack: added %d points for [%s][%s]", len(t), icaoId, callsign)
	w.Write([]byte(fmt.Sprintf("Added %d for %s\n", len(t), icaoId)))
}