router

package
v0.0.0-...-3a5708c Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package router provides basic means of switching between the wiki's different page types. Those types are, for example, viewing a page, editing a page, logging in etc., and are called "modes".

This package decides when to invoke the HTTP handler for which mode and provides logic for redirecting betweend those modes.

Template URLs

A special case are URLs to files that are part of gone's templates. These may reside in another namespace than the files delivered regularly, e.g. when template data from inside the gone binary is be used.

The question is here, how to distinguish those files from a given URL. This is either possible by a special path component, e.g. "/+template", or by a query parameter, e.g. "?template".

While making this decision, we should never break the spec in that a template can be a different resource than a regularly delivered file with the same name. Therefore, our means should be able to identify different resources.

This is possible with paths (of course), but as the spec states, also with query parameters. See RFC 3986 Sec. 3.4: "The query component contains non-hierarchical data that, along with data in the path component (Section 3.3), serves to identify a resource within the scope of the URI's scheme and naming authority (if any)."

As in gone, the path shall solely identify a file inside the content root, and we already use the notion of "modes" in query parameters, we decide to also use modes for templates.

Index

Constants

View Source
const (
	ModeView     Mode = ""
	ModeEdit          = "edit"
	ModeCreate        = "create"
	ModeLogin         = "login"
	ModeDelete        = "delete"
	ModeTemplate      = "template"
)

Mode-Constants give names to each mode the wiki application might be in. The mode names are used to identify the desired mode in a URL.

Variables

This section is empty.

Functions

func Is

func Is(m Mode, r *http.Request) bool

Is returns true, iff the given request specifies to open a resource in the given mode.

func Redirect

func Redirect(writer http.ResponseWriter, request *http.Request, location *url.URL)

func RedirectToEditMode

func RedirectToEditMode(writer http.ResponseWriter, request *http.Request)

func RedirectToViewMode

func RedirectToViewMode(writer http.ResponseWriter, request *http.Request)

func To

func To(m Mode, u *url.URL) *url.URL

To returns a URL that points to the same resource, but lets the wiki open it in given mode.

Types

type Mode

type Mode string

type Router

type Router struct {
	// contains filtered or unexported fields
}

Router encapsulates http.Handler instances for all relevant views and invokes the right one for each request.

func New

func New(
	viewer http.Handler,
	editor http.Handler,
	templateDeliverer http.Handler,
	authenticator http.Handler,
) *Router

New constructs a new instance ready to use.

func (Router) ServeHTTP

func (r Router) ServeHTTP(writer http.ResponseWriter, request *http.Request)

Jump to

Keyboard shortcuts

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