Example #1
0
func ShortUrlCreate(url string) (*ShortUrl, error) {
	s := &ShortUrl{URL: url}
	if err := db.DbMap.Insert(s); err != nil {
		return nil, err
	}
	s.Slug = key.GenKey(s.Id)
	go s.pushToRedis()
	return s, nil
}
Example #2
0
func ShortUrlById(id int64) (*ShortUrl, error) {
	v, err := db.DbMap.Get(ShortUrl{}, id)
	if err != nil || v == nil {
		return nil, err
	}
	s := v.(*ShortUrl)
	s.Slug = key.GenKey(s.Id)
	return s, nil
}