server

package
v0.0.0-...-d49ac33 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 28, 2021 License: BSD-3-Clause Imports: 11 Imported by: 0

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

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

func (*Server) Close

func (s *Server) Close() error

Close will call the servers close method and return any errors

func (*Server) Serve

func (s *Server) Serve(sig chan os.Signal) (err error)

Serve will listen and serve this app then exit when a signal has been received

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL