|
|
|
@ -37,7 +37,7 @@ func StreamToByte(stream io.Reader) []byte {
|
|
|
|
|
return buf.Bytes()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *Storage) Add(URL string) (string, error) {
|
|
|
|
|
func (s *Storage) Add(URL string, value interface{}) (string, error) {
|
|
|
|
|
// if the URL a valid URL?
|
|
|
|
|
/*if !govalidator.IsURL(URL) {
|
|
|
|
|
return "", errors.New("invalid url")
|
|
|
|
@ -57,6 +57,7 @@ func (s *Storage) Add(URL string) (string, error) {
|
|
|
|
|
token := hash[:hashShortestLen]
|
|
|
|
|
s.Token[token] = hash
|
|
|
|
|
s.Url[hash] = shrt{URL: URL, Token: token}
|
|
|
|
|
value = s.Url[hash]
|
|
|
|
|
return token, nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -69,9 +70,12 @@ func (s *Storage) Remove(URL string) error {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get returns the URL for the given token
|
|
|
|
|
func (s *Storage) Get(token string) (string, error) {
|
|
|
|
|
if val, ok := s.Token[token]; ok {
|
|
|
|
|
return s.Url[val].URL, nil
|
|
|
|
|
func (s *Storage) Get(token string, value interface{}) bool {
|
|
|
|
|
if hash, ok := s.Token[token]; ok {
|
|
|
|
|
fmt.Printf("Url gefunden %s mit Hash: %v \n", s.Url[hash].URL, hash)
|
|
|
|
|
value = s.Url[hash].URL
|
|
|
|
|
fmt.Printf("Value: %V \n", value)
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
return "", ErrNotFound
|
|
|
|
|
return false
|
|
|
|
|
}
|