routes

package
v0.0.0-...-8aa12d4 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2023 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddIndexRoute

func AddIndexRoute(r Route)

AddIndexRoute ensures that the general path is added last for matching order

func AddRoute

func AddRoute(rt Route)

AddRoute registers a new route to the main router. Routes should register themselves on init.

func AddSubroute

func AddSubroute(namespace string, rts []Route)

AddSubroute adds a subroute with the given namespace and paths to handle to the main router. Subroutes should be added on init.

func AppHome

func AppHome() string

AppHome returns the location of the home directory

func Auth

func Auth(next http.Handler) http.Handler

Auth ensures that the requester is authenticated and authorized to access the resource. Failures are logged as well.

func EnableDebugMode

func EnableDebugMode(enable bool)

EnableDebugMode allows for detailed output and full error messages to be sent to clients. NOTE: do not use in production!

func GetRouter

func GetRouter() http.Handler

GetRouter returns the main Router

func HandleForbidden

func HandleForbidden(w http.ResponseWriter, r *http.Request)

HandleForbidden serves a HTTP 403 Forbidden page to the user, denying access to the resource

func Log

func Log(next http.Handler) http.Handler

Log records the resource requested and the origin of the request. All routes should call Log (directly or indirectly)

func LoginRequired

func LoginRequired(next http.Handler) http.Handler

LoginRequired is a shortcut to call both Log and Auth middlewares.

func RenderError

func RenderError(w http.ResponseWriter, err errors.HttpError)

RenderError writes out user errors and genericized server errors to the client

func RenderPage

func RenderPage(w http.ResponseWriter, url string) error

RenderPage writes the page contents to the response body

func RenderTemplate

func RenderTemplate(w http.ResponseWriter, contentTemplate string, data interface{}) error

RenderTemplate executes the given template body

func ServeFile

func ServeFile(w http.ResponseWriter, r *http.Request)

ServeFile writes the requested file to the response

func SetAppHome

func SetAppHome(dir string)

SetAppHome sets the location of the home directory

func SetStaticDir

func SetStaticDir(dir string)

SetStaticDir adds a file server to handle static files in the specified directory

Types

type Route

type Route struct {
	Path    string
	Handler http.Handler
}

Route defines the URL pattern that it will handle and provides the function to do so

func New

func New(path string, handler http.Handler) Route

New creates a new Route

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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