|
|
|
@ -17,7 +17,7 @@ type Data struct {
|
|
|
|
|
Token string `json:"token"`
|
|
|
|
|
Meta `json:"meta"`
|
|
|
|
|
FavIconLink string `json:"favicon_url"`
|
|
|
|
|
HTTPStatusCode string `json:"http_code"`
|
|
|
|
|
HTTPStatusCode int `json:"http_code"`
|
|
|
|
|
Category string `json:"category"`
|
|
|
|
|
Created string `json:"created_at"`
|
|
|
|
|
Clicks int64 `json:"clicks"`
|
|
|
|
@ -41,7 +41,7 @@ func (s *Store) Short(URL string, value *string) error {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create a sha256 Hash from the URL
|
|
|
|
|
d.Hash = fmt.Sprintf("%x", sha256.Sum256([]byte(d.OriginalURL)))
|
|
|
|
|
d.Hash = fmt.Sprintf("%x", sha256.Sum256([]byte(d.URLFetched)))
|
|
|
|
|
|
|
|
|
|
// Check if the URL already in the Storage
|
|
|
|
|
if ok := s.Exist(&d); ok {
|
|
|
|
@ -79,10 +79,10 @@ func (s *Store) Exist(d *Data) bool {
|
|
|
|
|
|
|
|
|
|
// Returns the URL for the given token
|
|
|
|
|
func (s *Store) Redirect(token string) (string, bool) {
|
|
|
|
|
if shrt, ok := s.Token[token]; ok {
|
|
|
|
|
s.Token[token].Clicks += 1
|
|
|
|
|
if data, ok := s.Token[token]; ok {
|
|
|
|
|
data.Clicks += 1
|
|
|
|
|
s.Save()
|
|
|
|
|
return shrt.OriginalURL, true
|
|
|
|
|
return data.URLFetched, true
|
|
|
|
|
}
|
|
|
|
|
return "", false
|
|
|
|
|
}
|
|
|
|
|