Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Database ¶
type Database interface { Set(ctx context.Context, key, value string) error Get(ctx context.Context, key string) (string, error) }
Database describes a data store used by Shortener to store shortened URLs data
type Shortner ¶
type Shortner struct {
// contains filtered or unexported fields
}
Shortener provides http.HandlerFunc methods to save and get shortened URLs
func (Shortner) GetURL ¶
func (s Shortner) GetURL(w http.ResponseWriter, r *http.Request)
GetURL reads the `to` query parameter, looks it up on Database if it finds a URL for it, the response is a temporary redirect to this URL Exmaple: www.example.com/go?to=uuidv4
func (Shortner) SaveURL ¶
func (s Shortner) SaveURL(w http.ResponseWriter, r *http.Request)
SaveURL reads the `url` query string, generates a token for it and saves them using a Database. Example: www.example.com/some-path?url=https://tiago.life
Click to show internal directories.
Click to hide internal directories.