Documentation ¶
Index ¶
- Constants
- func EnsurePrefix(originalURL string) (string, error)
- type App
- func (a *App) Create(req *CreateRequest, hasher Hasher) (string, error)
- func (a *App) CreateHandler(w http.ResponseWriter, r *http.Request)
- func (a *App) CreateJSONHandler(w http.ResponseWriter, r *http.Request)
- func (a *App) HealthHandler(w http.ResponseWriter, r *http.Request)
- func (a *App) Init(store db.DBer, portNum string) error
- func (a *App) RedirectHandler(w http.ResponseWriter, r *http.Request)
- func (a *App) RedirectJSONHandler(w http.ResponseWriter, r *http.Request)
- func (a *App) RootHandler(w http.ResponseWriter, r *http.Request)
- func (a *App) Run() error
- type CreateRequest
- type CreateResponse
- type Hasher
- type MD5Hash
- type RedirectResponse
- type ResultTemplateData
Constants ¶
View Source
const ( LenShortened = 6 JSONMimeType = "application/json" ContentType = "Content-Type" )
Variables ¶
This section is empty.
Functions ¶
func EnsurePrefix ¶
TODO: maybe we should pass around a net.url.URL object rather than a string
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
func (*App) CreateHandler ¶
func (a *App) CreateHandler(w http.ResponseWriter, r *http.Request)
CreateHandler provides the create functionality for the website
func (*App) CreateJSONHandler ¶
func (a *App) CreateJSONHandler(w http.ResponseWriter, r *http.Request)
CreateJSONHandler handles the creation of new shortened URLS curl localhost:8080/v1/create -d '{"original_url": "http://foobarcat.blogspot.com"}' TODO: Add test case where mandatory field original_url is missing
func (*App) HealthHandler ¶
func (a *App) HealthHandler(w http.ResponseWriter, r *http.Request)
func (*App) RedirectHandler ¶
func (a *App) RedirectHandler(w http.ResponseWriter, r *http.Request)
TODO: refactor out common code amongst Redirect* handlers TODO: Test this handler
func (*App) RedirectJSONHandler ¶
func (a *App) RedirectJSONHandler(w http.ResponseWriter, r *http.Request)
RedirectJSONHandler handles GET access to shortened urls, this endpoint is publically available curl http://localhost:8080/v1/redirect/foo TODO: respond with correct status codes
func (*App) RootHandler ¶
func (a *App) RootHandler(w http.ResponseWriter, r *http.Request)
type CreateRequest ¶
type CreateRequest struct {
OriginalURL string `json:"original_url"`
}
type CreateResponse ¶
type RedirectResponse ¶
Click to show internal directories.
Click to hide internal directories.