|
|
@ -5,44 +5,37 @@ Shrt is a url shortner writen in Go and by (Polr)[https://polr.me/index.php].
|
|
|
|
|
|
|
|
|
|
|
|
## Features
|
|
|
|
## Features
|
|
|
|
|
|
|
|
|
|
|
|
[x] No duplicated URL
|
|
|
|
* [x] No duplicated URL
|
|
|
|
[x] Simple UI
|
|
|
|
* [x] Simple UI
|
|
|
|
[x] DB simple json file
|
|
|
|
* [x] DB simple json file
|
|
|
|
[x] Count URL views
|
|
|
|
* [x] Count URL views
|
|
|
|
[] Statistiks
|
|
|
|
* [] Statistiks
|
|
|
|
[] Delete URL
|
|
|
|
* [] Delete URL
|
|
|
|
[] Login
|
|
|
|
* [] Login
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Problem
|
|
|
|
## Restful API
|
|
|
|
Problem liegt derzeit bei der Verwendung von shrt.Get mit der übergabe eines inteface.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Short an URL
|
|
|
|
```
|
|
|
|
```
|
|
|
|
package main
|
|
|
|
GET: http://example.com/api/action/shorten?key=API_KEY_HERE&url=http://example.de/shortening/main?q=5x
|
|
|
|
|
|
|
|
|
|
|
|
...
|
|
|
|
Response:
|
|
|
|
|
|
|
|
{ "action": "shorten",
|
|
|
|
var redirect string
|
|
|
|
"result": "https://example.com/5kq" }
|
|
|
|
if ok := shrt.Get(token, &redirect); ok {
|
|
|
|
|
|
|
|
// do something with the redirect.
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
Entgegen genommen wird es bei `lib/shrt.go`:
|
|
|
|
Lookup for existing URL
|
|
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
```
|
|
|
|
// Get returns the URL for the given token
|
|
|
|
GET: http://example.com/api/action/lookup?key=API_KEY_HERE&url_ending=5kq
|
|
|
|
func (s *Storage) Get(token string, value interface{}) bool {
|
|
|
|
|
|
|
|
if hash, ok := s.Token[token]; ok {
|
|
|
|
Response:
|
|
|
|
fmt.Printf("Url gefunden %s mit Hash: %v \n", s.Url[hash].URL, hash)
|
|
|
|
{ "action":"lookup",
|
|
|
|
value = s.Url[hash].URL
|
|
|
|
"result": {
|
|
|
|
fmt.Printf("Value: %V \n", value)
|
|
|
|
"long_url": "http://example.de/shortening/main?q=5x",
|
|
|
|
return true
|
|
|
|
"created_at": "2017-05-12 22:48:40.997520107 +0200 CEST",
|
|
|
|
}
|
|
|
|
"clicks":"0"
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
Ich dachte eigentlich ich könne redirect damit manipulieren wenn ich es als pointer auf redirect übergebe aber das scheint nicht so zu sein....
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|