ae

package module
v0.0.0-...-4ecb35b Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2017 License: MIT Imports: 19 Imported by: 0

README

Warning

This library is more unstable than Trump's presidency

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoMatch = errors.New("path and pattern don't match part count")
)

Errors

Functions

func LogError

func LogError(c context.Context, msg string, err error) error

func NewV4UUID

func NewV4UUID() string

NewV4UUID returns random generated UUID.

func OriginMiddleware

func OriginMiddleware(allowed []string) func(context.Context, http.ResponseWriter, *http.Request) context.Context

OriginMiddleware returns a middleware function that validates the origin header within the request matches the allowed values

Types

type ErrModelValidation

type ErrModelValidation struct {
	Message string
}

func NewValidationError

func NewValidationError(msg string) ErrModelValidation

func (ErrModelValidation) Error

func (mv ErrModelValidation) Error() string

type Handler

type Handler struct {
	Ctx context.Context
	Req *http.Request
	Res http.ResponseWriter
	// contains filtered or unexported fields
}

Handler struct designed to be extended by more specific url handlers

func DefaultHandler

func DefaultHandler() Handler

DefaultHandler uses the default config settings

func NewRootHandler() rootHandler {
	return rootHandler{Handler: handler.Default()}
}

func NewHandler

func NewHandler(c *HandlerConfig) Handler

NewHandler allows one to override the default configuration settings.

func NewRootHandler() rootHandler {
	return rootHandler{Handler: handler.New(&handler.Config{
		LayoutPath: "layouts",
	})}
}

func (*Handler) Abort

func (h *Handler) Abort(statusCode int, err error)

Abort is called when pre-maturally exiting from a handler function due to an error. A detailed error is delivered to the client and logged to provide the details required to identify the issue.

func (*Handler) AddHelper

func (h *Handler) AddHelper(name string, fn interface{})

AddHelper allows one to add additional helpers to a handler. Use this when a handler needs a less common helper.

func (*Handler) AddHelpers

func (h *Handler) AddHelpers(helpers map[string]interface{})

AddHelpers sets the html.template functions for the handler. This method should be called once to intialize the handler with a set of common template helpers used throughout the app.

func (*Handler) Auth

func (h *Handler) Auth(allowed bool, op func())

Auth is a helper for the handler operation method that will only call on the operation if allowed

func (*Handler) Bind

Bind must be called at the beginning of every request to set the required references

func (*Handler) Flash

func (h *Handler) Flash() string

Flash gets the flash value

func (*Handler) Header

func (h *Handler) Header(name string) string

Header gets the request header value

func (*Handler) Redirect

func (h *Handler) Redirect(str string, args ...interface{})

Redirect is a simple wrapper around the core http method

func (*Handler) Render

func (h *Handler) Render(path string, data interface{})

Render pre-caches and renders template.

func (*Handler) RenderError

func (h *Handler) RenderError(status int, err *ServerError)

RenderError will render a the file that corresponds to the status code ex. http.InternalServerError will render 500.html

func (*Handler) RenderTemplate

func (h *Handler) RenderTemplate(tmplPath string, data interface{}, opts RenderOptions)

RenderTemplate renders the template without any layout

func (*Handler) SendStatus

func (h *Handler) SendStatus(status int)

SendStatus writes the passed in status to the response without any data

func (*Handler) SetCookie

func (h *Handler) SetCookie(c *http.Cookie)

SetCookie is a simple wrapper around the http.SetCookie methoe

func (*Handler) SetETag

func (h *Handler) SetETag(val interface{})

SetETag sets the etag with the md5 value

func (*Handler) SetExpires

func (h *Handler) SetExpires(t time.Time)

SetExpires sets the Expires response header with a properly formatted time value

func (*Handler) SetExpiresIn

func (h *Handler) SetExpiresIn(d time.Duration)

SetExpiresIn is a helper to simplify the calling of SetExpires

func (*Handler) SetFlash

func (h *Handler) SetFlash(msg string, args ...interface{})

SetFlash sets a temporary message into a response cookie, that after being viewed will be removed, to prevent it from being viewed again.

func (*Handler) SetHeader

func (h *Handler) SetHeader(name, value string)

SetHeader sets a response header value

func (*Handler) SetLastModified

func (h *Handler) SetLastModified(t time.Time)

SetLastModified sets the Last-Modified header in the RFC1123 time format

func (*Handler) ToJSON

func (h *Handler) ToJSON(data interface{})

ToJSON encodes an interface into the response writer with a default http status code of 200

func (*Handler) ToJSONWithStatus

func (h *Handler) ToJSONWithStatus(data interface{}, status int)

ToJSONWithStatus json encodes an interface into the response writer with a custom http status code

func (*Handler) ValidateOrigin

func (h *Handler) ValidateOrigin(allowed []string)

ValidateOrigin is a helper method called within the ServeHTTP method on OPTION requests to validate the allowed origins

type HandlerConfig

type HandlerConfig struct {
	// File name of the layout
	LayoutFileName string
	// Path, relative to the app root, of layouts
	LayoutPath string
	// Path, relative to the app root, of layouts
	ViewPath string
	// ???
	ParentLayoutName string
}

HandlerConfig contains the custom handler configuration settings

type Model

type Model struct {
	Key *datastore.Key `json:"key" datastore:"-"`
}

Model has the common key property

type RenderOptions

type RenderOptions struct {
	// http status to return in the response
	Status int

	// template functions
	FuncMap template.FuncMap

	// parent layout paths to render the defined view within
	Parents []string

	// the defined *name* to render
	// 	{{define "layout"}}...{{end}}
	Name string
}

RenderOptions contain the optional data items for rendering

type Route

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

Route type is a simple wrapper around the public methods to eliminate the need of passing the url to each of the methods.

func NewRoute

func NewRoute(r *http.Request) Route

NewRoute creates a route

func (*Route) Contains

func (r *Route) Contains(val string) bool

Contains indicates if the named param exists within the url

func (*Route) Get

func (r *Route) Get(name string) string

Get returns the named param from the url

func (*Route) Key

func (r *Route) Key(name string) *datastore.Key

Key wraps the public Key() method

func (*Route) Matches

func (r *Route) Matches(method, pattern string) bool

Matches checks if the request url matches the passed in pattern. Patterns need to define the arguments at least one leading `:` character. ex.

/foo/:var/bar

This method does not validate pattern argument data formats.

func (*Route) MatchesPath

func (r *Route) MatchesPath(pattern string) bool

MatchesPath checks for path matches and allows for wildcards

type ServerError

type ServerError struct {
	Status                       int
	Message, Details, StackTrace string
}

type Store

type Store struct {
	TableName string
}

Store is the include common attrs and methods for other *model types

func NewStore

func NewStore(tableName string) Store

NewStore is a helper to create a base store

func (Store) Create

func (s Store) Create(c context.Context, data interface{}, parentKey *datastore.Key) (*datastore.Key, error)

Create creates the model

func (Store) Delete

func (s Store) Delete(c context.Context, key *datastore.Key) error

Delete deletes the record and clears the memcached record

func (Store) Get

func (s Store) Get(c context.Context, key *datastore.Key, dst interface{}) (*datastore.Key, error)

Get attempts to return the cached model, if no cached data exists, it then fetches the data from the database and caches the data

func (Store) Update

func (s Store) Update(c context.Context, key *datastore.Key, data interface{}) error

Update updates the model and clears the memcached data

Directories

Path Synopsis
que

Jump to

Keyboard shortcuts

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