func incrCount(tde *kv.TiedotEngine) int64 { mu.Lock() defer mu.Unlock() counter := new(Counter) id, err := tde.Query(counterCollection).Has(kv.Path{"Count"}).OneInto(counter) if err == kv.ErrNotFound { log.Warning("Counter not found, saving new one.") _, err = tde.Insert(counterCollection, Counter{Count: 1}) if err != nil { log.Errorf("Error saving new counter err=%s", err.Error()) } r, err := tde.All(counterCollection) log.V(3).Infof("total of %d results=%v, err=%v", len(r), r, err) return 1 } if err != nil { log.Error("Failure getting counter err:" + err.Error()) panic(err) } counter.Count++ err = tde.Update(counterCollection, id, counter) if err != nil { log.Error("Failure updating counter err:" + err.Error()) panic(err) } return counter.Count }
func saveShortened(s Shortened, tde *kv.TiedotEngine) error { _, err := tde.Insert(urlCollection, s) return err }