Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Index ¶
func Index(w http.ResponseWriter, r *http.Request)
Index will serve the index of the web application
func Shorten ¶
func Shorten(rep repo.Repository) http.HandlerFunc
Shorten a url by hashing it and writing it to a repository
func Url ¶
func Url(rep repo.Repository) http.HandlerFunc
Url will look up the hash of a url in a repository and redirect the client if found
Types ¶
type Route ¶
type Route struct {
// contains filtered or unexported fields
}
Route defines a handler that gets called when the corresponding regex pattern matches
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router will route requests to their respective handlers
func NewRouter ¶
func NewRouter() *Router
NewRouter creates a new router with a default handle of 404
func (*Router) HandlerFunc ¶
func (ro *Router) HandlerFunc(pattern string, handle http.HandlerFunc)
HandlerFunc will register a new route within the router given the regex pattern to match and the handle to call
func (*Router) ServeHTTP ¶
func (ro *Router) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP satisfies the http.Handle interface. It will call a routes handler if its regex matches against the requests URL path
func (Router) SetDefaultHandle ¶
func (ro Router) SetDefaultHandle(h http.HandlerFunc)
SetDefaultHandle will set the default handle to h
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server will register routes and serve this web application
func NewServer ¶
func NewServer(addr string, r repo.Repository) *Server
NewServer will create a new server given the address to listen on and a repository to store urls