Documentation ¶
Index ¶
- func Index(w http.ResponseWriter, r *http.Request, _ httprouter.Params)
- func NewRouter(db *database.Database) http.Handler
- func Redirect(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
- func RedirectURL(db *database.Database) httprouter.Handle
- func ShortenURL(db *database.Database) httprouter.Handle
- type ErrorResp
- type MessageResp
- type ShortenReq
- type ShortenResp
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Index ¶
func Index(w http.ResponseWriter, r *http.Request, _ httprouter.Params)
Index handles requests for / path
func NewRouter ¶
NewRouter creates a new httprouter Router, sets the handler for each route and adds middleware for enabling CORS with the default options.
Returns an http.Handler
func Redirect ¶
func Redirect(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
Redirect handles requests for /redirect path
func RedirectURL ¶
func RedirectURL(db *database.Database) httprouter.Handle
RedirectURL handles requests for /redirect/:short_url path
func ShortenURL ¶
func ShortenURL(db *database.Database) httprouter.Handle
ShortenURL handles requests for /shorten path
Types ¶
type ErrorResp ¶
type ErrorResp struct {
Error string `json:"error"`
}
ErrorResp represents the JSON response that will be sent on errors.
type MessageResp ¶
type MessageResp struct {
Message string `json:"message"`
}
MessageResp represents the JSON response that will be sent as a message.
type ShortenReq ¶
type ShortenReq struct {
LongURL string `json:"long_url"`
}
ShortenReq represents the JSON body of the request that will be decoded, on the shorten endpoint.
type ShortenResp ¶
ShortenResp represents the JSON response that will be sent, on the shorten endpoint.