Documentation ¶
Overview ¶
Package gum provides the gum personal short URL resolver.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler interface { // Register the handler with the provided ServeMux. This method will be // called when the handler is added to the mux, and allows the // handler to specify the kinds of short URLs it can handle. // Typically, but not always, this will be URLs of the form "/x" and // /x/*" where x is a particular content type. Register(*http.ServeMux) error // Mappings provides a write only channel for the handler to write // static Mapping values onto. These mappings are then registered with // and the redirects handled by the Server. Mappings(chan<- Mapping) error }
A Handler serves requests for short URLs. Typically, a handler will register itself for an entire path prefix using the Register func, or provide a list of static mappings using the Mappings func.
type Mapping ¶
type Mapping struct { // ShortPath is the path of the short URL (including leading slash) to // be mapped. ShortPath string // Permalink is the destination URL being mapped to. Permalink string }
Mapping represents a mapping between a short URL path and the permalink URL it is for.
type RedirectHandler ¶
type RedirectHandler struct { // Prefix is the path component prefix this handler should handle. // Prefix should not contain leading or trailing slashes. Prefix string // Destination is the base URL to redirect requests to. If Destination // includes a path, it should typically include a trailing slash. Destination *url.URL // Status is the HTTP status to return in redirect responses. Status int }
RedirectHandler redirects requests that match a given path component prefix to a specified destination base URL. For example, given a RedirectHandler:
RedirectHandler{ Prefix: "x", Destination: "http://example/", }
The following URLs would be redirected:
/x => http://example/ /x/ => http://example/ /x/a/b?c=d => http://example/a/b?c=d
The request URL "/x123" would not be handled by this handler.
func NewRedirectHandler ¶
func NewRedirectHandler(prefix, destination string) (*RedirectHandler, error)
NewRedirectHandler constructs a new RedirectHandler with the specified prefix and destination, and a 301 (Moved Permanently) response status.
func (*RedirectHandler) Mappings ¶
func (h *RedirectHandler) Mappings(mappings chan<- Mapping) error
Mappings implements the Handler interface.
func (*RedirectHandler) Register ¶
func (h *RedirectHandler) Register(mux *http.ServeMux) error
Register this handler with the provided ServeMux.
func (*RedirectHandler) ServeHTTP ¶
func (h *RedirectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is a short URL redirection server.
func (*Server) AddHandler ¶
AddHandler adds the provided Handler to the server.
type StaticHandler ¶
type StaticHandler struct {
// contains filtered or unexported fields
}
StaticHandler handles short URLs parsed from static HTML files. Files are parsed and searched for rel="shortlink" and rel="canonical" links. If both are found, a redirect is registered for the pair.
func NewStaticHandler ¶
func NewStaticHandler(base string) (*StaticHandler, error)
NewStaticHandler constructs a new StaticHandler with the specified base path of HTML files.
func (*StaticHandler) Mappings ¶
func (h *StaticHandler) Mappings(mappings chan<- Mapping) error
Mappings implements Handler.