fuse

package module
v0.0.0-...-2faf048 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2015 License: MIT Imports: 11 Imported by: 1

Documentation

Overview

Package fuse is a web framework with sane conventions. These conventions remove some of the boilerplate that naturally arises from using Go for web development. Fuse automatically:

  • serves files from the public directory
  • loads templates from the template directory
  • loads and saves sessions

This means that each controller is more succinct and to the point.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Logger

func Logger(c *Context)

Logger is a middleware component that logs each request to the log package's output.

Types

type Context

type Context struct {
	// Request is the original http.Request.
	Request *http.Request
	// ResponseWriter is the original http.ResponseWriter.
	ResponseWriter http.ResponseWriter
	// Params is a map of the path parameters.
	Params map[string]string
	// Form holds all of the form data from the URL query and the POST/PUT
	// data.
	Form url.Values
	// PostForm holds only the POST/PUT data.
	PostForm url.Values
	// InData provides a way for middleware to pass data to handlers.
	InData map[string]interface{}
	// OutData is used to render dynamic content.  Calls to Context.Html and
	// Context.Json use this data.
	OutData map[string]interface{}
	// Session contains the current request's session data.
	Session map[interface{}]interface{}
	// contains filtered or unexported fields
}

Context holds all necessary information about an incoming request.

func (*Context) Html

func (c *Context) Html(code int, name string)

Html executes the named template with the given HTTP code. It uses the context's OutData in the template.

func (*Context) HtmlOk

func (c *Context) HtmlOk(name string)

Html executes the named template with the 200 OK HTTP code. It uses the context's OutData in the template.

func (*Context) Json

func (c *Context) Json(code int)

Json encodes the context's OutData to JSON with the given HTTP code.

func (*Context) JsonOk

func (c *Context) JsonOk()

Json encodes the context's OutData to JSON with the 200 OK HTTP code.

func (*Context) Next

func (c *Context) Next()

Next calls the next middleware in the chain. If called from the handler, it will panic.

func (*Context) SeeOther

func (c *Context) SeeOther(location string)

SeeOther redirects the request to the location using the 303 See Other HTTP code.

func (*Context) Text

func (c *Context) Text(code int, text string)

Text writes the text to the response with the given HTTP code.

func (*Context) TextOk

func (c *Context) TextOk(text string)

TextOk writes the text to the response with the 200 OK HTTP code.

type Engine

type Engine struct {
	// NotFound is called whenever a request comes in that isn't mapped to a
	// handler and doesn't correspond to a file name in the public directory.
	NotFound Handler
	// Panic is called whenever a request panics.
	Panic Handler
	// PublicDir is the directory which holds all files that are publicly
	// accessible.  The default is "public".
	PublicDir string
	// TempalteGlob is the glob that defines which files to parse as HTML
	// templates.  The default is "templates/*.tpl"
	TemplateGlob string
	// contains filtered or unexported fields
}

Engine is the Fuse server. It should always be created using the fuse.New function.

func New

func New(sessionSecret []byte) *Engine

New returns an initialized instance of *Engine.

func (*Engine) DELETE

func (e *Engine) DELETE(path string, handler Handler)

DELETE defines a route for DELETE requests to the handler. See GET for information about path parameters.

func (*Engine) GET

func (e *Engine) GET(path string, handler Handler)

GET defines a route for GET requests to the handler. The path can contain parameters prefixed with a colon (:). For example, the following requests would all be routed to the handler if we define the path as /user/:name

/user/foo
/user/bar
/user/baz

However, the following paths would not be routed.

/user
/user/
/user/foo/profile
/profile/user/foo

func (*Engine) HEAD

func (e *Engine) HEAD(path string, handler Handler)

HEAD defines a route for HEAD requests to the handler. See GET for information about path parameters.

func (*Engine) POST

func (e *Engine) POST(path string, handler Handler)

POST defines a route for POST requests to the handler. See GET for information about path parameters.

func (*Engine) PUT

func (e *Engine) PUT(path string, handler Handler)

PUT defines a route for PUT requests to the handler. See GET for information about path parameters.

func (*Engine) Run

func (e *Engine) Run(addr string)

Run calls ListenAndServe.

func (*Engine) Use

func (e *Engine) Use(handler Handler)

Use adds the handler to the end of the middleware chain.

type Handler

type Handler func(c *Context)

Handler is the type of function used to handle all requests in Fuse, including middleware.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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