zaiuz

package module
v0.0.0-...-716bc83 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2014 License: BSD-2-Clause Imports: 7 Imported by: 4

README

Build Status

ZAIUZ

WIP Forklift for the excellent gorilla web toolkit.

LICENSE

BSD 2-Clause (see the LICENSE file for more info)

Documentation

Overview

Package zaiuz provides glue code implementation that ties together various components of the excellent Gorilla web toolkit (http://www.gorillatoolkit.org) to make developing typical MVC-style website faster and easier using as many common conventions as will not clutter the package.

Index

Constants

View Source
const InitialContextCapacity = 4

Initial capacity for the context internal storage.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action func(ctx *Context) Result

Action is the main interaction unit of zaiuz. This is zaiuz's analog to the standard http.ServeHTTP method. Most methods that work on the Context should follows the same function signature.

type Context

type Context struct {
	Request        *http.Request
	ResponseWriter http.ResponseWriter
	// contains filtered or unexported fields
}

The basic Context structure encapsulates request and response objects that would normally be supplied to a http.ServeHTTP method as well as encapsulating a small map for storing and passing data between modules inside a single request execution context.

func NewContext

func NewContext(w http.ResponseWriter, r *http.Request) *Context

Creates a new context.

func (*Context) Delete

func (c *Context) Delete(key string)

Removes an object tied to the specified key from the context.

func (*Context) Get

func (c *Context) Get(key string) interface{}

Gets an object from the context tied to the specified key.

func (*Context) GetOk

func (c *Context) GetOk(key string) (interface{}, bool)

Gets an object from the context tied to the specified key, also returns an additional boolean indicating wether the get was successful.

func (*Context) Has

func (c *Context) Has(key string) bool

Checks wether or not the context contains the specified key. You can also use GetOk to perform the checking and retreival in one operation.

func (*Context) Set

func (c *Context) Set(key string, value interface{})

Saves an object the the context and associate it to the specified key.

type Filter

type Filter func(action Action) Action

ActionFilter provides a way to wraps an existing actions to modifies or adds to the functionality. ActionFilter is functionally equivalent to traditional middlewares.

func DudFilter

func DudFilter() Filter

DudFilter returns a Filter that have no effect. Mostly only useful for testing.

type Hash

type Hash string

Represents a hashed string usually used for storing passwords. This type implements driver.Valuer and sql.Scanner so you can use this as your model's password hash type directly. The underlying algorithm use google's bcrypt library.

func NewHash

func NewHash(original string) Hash

Returns a new hash from a string.

func (Hash) MatchOriginal

func (hash Hash) MatchOriginal(original string) bool

Returns wether or not the receiver hash is the hash of the given original string. Use this method to compare user's password input with stored hash value.

func (*Hash) Scan

func (hash *Hash) Scan(src interface{}) (e error)

func (Hash) Value

func (hash Hash) Value() (driver.Value, error)

type Key

type Key string

Represents a GUID database key. This type implements driver.Valuer and sql.Scanner so you can use this as your model's Key type directly.

func NewKey

func NewKey() Key

Returns a new GUID key.

func (*Key) Scan

func (key *Key) Scan(src interface{}) (e error)

func (Key) Value

func (key Key) Value() (driver.Value, error)

TODO: validate

type NullKey

type NullKey struct{ sql.NullString }

Analog to sql.NullString for Key

func NewNullKey

func NewNullKey() NullKey

func (NullKey) Key

func (nk NullKey) Key() Key

type Result

type Result interface {
	Render(c *Context) error
}

type Router

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

Router is a wrapper over Gorrila web toolkit's mux router (http://www.gorillatoolkit.org/pkg/mux) that provides helpers that work with standard zaiuz Action function signature as well as Filters.

func NewRouter

func NewRouter() *Router

func (*Router) Filters

func (router *Router) Filters() []Filter

Retreive all modules included into this router so far. Also resolve parent's list of modules if called from a subrouter.

func (*Router) Get

func (router *Router) Get(path string, action Action) *Router

Maps an Action to the specified URL Path and HTTP GET method.

func (*Router) GetPost

func (router *Router) GetPost(path string, action Action) *Router

Maps an Action to the specified URL Path and HTTP GET _and_ POST method.

func (*Router) Include

func (router *Router) Include(filters ...Filter)

Include a Filter in the current router for all mapped (and future) actions.

func (*Router) Parent

func (router *Router) Parent() *Router

Parent() method returns the parent router if this is a child router, or nil otherwise.

func (*Router) Post

func (router *Router) Post(path string, action Action) *Router

Maps an Action to the specified URL Path and HTTP POST method.

func (*Router) Router

func (router *Router) Router() *mux.Router

Router() method returns the internal mux.Router from gorilla web toolkit for direct access. This method is not recommended unless you want to access specifici functionality provided by the gorilla web toolkit that does not yet have an equivalent in zaiuz.

func (*Router) ServeHTTP

func (router *Router) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Router) Static

func (router *Router) Static(urlPath, filePath string) *Router

func (*Router) Subrouter

func (router *Router) Subrouter(path string) *Router

Creates a child router. Analogous to calling mux's Router.Subrouter function but also carry over all the Filters included so far as well. Filters added in the subrouter only run inside the subrouter.

Jump to

Keyboard shortcuts

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