func LongURL(short string, tde *kv.TiedotEngine) (*Shortened, error) { // ignore the ID for now, we don't really need it out := new(Shortened) _, err := tde.Query("short.url").Equals(kv.Path{"Short"}, base62.DecodeString(short)).OneInto(out) log.Infof("Read one into %+v error:%v", out, err) if err != nil { return nil, err } return out, nil }
func remove(w http.ResponseWriter, r *http.Request, tde *kv.TiedotEngine, params martini.Params) (int, []byte) { short := params["short"] _, err := tde.Query(urlCollection).Equals(kv.Path{"Short"}, base62.DecodeString(short)).Delete() if err != nil { log.Error("Failure deleting URL /" + short + " err:" + err.Error()) return 500, M{ "message": "Could not delete URL /" + short, "error": err.Error(), }.JSON() } log.V(1).Info("Deleted URL /" + short) return 200, M{ "deleted": M{"short": short}, }.JSON() }
func incrHits(tde *kv.TiedotEngine, key string) uint64 { mu.Lock() defer mu.Unlock() short := new(Shortened) id, err := tde.Query(urlCollection).Equals( kv.Path{"Short"}, base62.DecodeString(key), ).OneInto(short) if err == kv.ErrNotFound { log.Warningf("Short URL %s not found", key) return 0 } else if err != nil { log.Errorf("Failure getting shortened URL key=%s err:%v", key, err) return 0 } short.HitCount++ err = tde.Update(urlCollection, id, short) if err != nil { log.Error("Failure updating hitcount key=%s err=%s", key, err.Error()) return 0 } return short.HitCount }