Documentation ¶
Index ¶
- Variables
- func LogError(c context.Context, msg string, err error) error
- func NewV4UUID() string
- func OriginMiddleware(allowed []string) func(context.Context, http.ResponseWriter, *http.Request) context.Context
- type ErrModelValidation
- type Handler
- func (h *Handler) Abort(statusCode int, err error)
- func (h *Handler) AddHelper(name string, fn interface{})
- func (h *Handler) AddHelpers(helpers map[string]interface{})
- func (h *Handler) Auth(allowed bool, op func())
- func (h *Handler) Bind(c context.Context, w http.ResponseWriter, r *http.Request)
- func (h *Handler) Flash() string
- func (h *Handler) Header(name string) string
- func (h *Handler) Redirect(str string, args ...interface{})
- func (h *Handler) Render(path string, data interface{})
- func (h *Handler) RenderError(status int, err *ServerError)
- func (h *Handler) RenderTemplate(tmplPath string, data interface{}, opts RenderOptions)
- func (h *Handler) SendStatus(status int)
- func (h *Handler) SetCookie(c *http.Cookie)
- func (h *Handler) SetETag(val interface{})
- func (h *Handler) SetExpires(t time.Time)
- func (h *Handler) SetExpiresIn(d time.Duration)
- func (h *Handler) SetFlash(msg string, args ...interface{})
- func (h *Handler) SetHeader(name, value string)
- func (h *Handler) SetLastModified(t time.Time)
- func (h *Handler) ToJSON(data interface{})
- func (h *Handler) ToJSONWithStatus(data interface{}, status int)
- func (h *Handler) ValidateOrigin(allowed []string)
- type HandlerConfig
- type Model
- type RenderOptions
- type Route
- type ServerError
- type Store
- func (s Store) Create(c context.Context, data interface{}, parentKey *datastore.Key) (*datastore.Key, error)
- func (s Store) Delete(c context.Context, key *datastore.Key) error
- func (s Store) Get(c context.Context, key *datastore.Key, dst interface{}) (*datastore.Key, error)
- func (s Store) Update(c context.Context, key *datastore.Key, data interface{}) error
Constants ¶
This section is empty.
Variables ¶
var (
ErrNoMatch = errors.New("path and pattern don't match part count")
)
Errors
Functions ¶
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 ¶
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 ¶
AddHelper allows one to add additional helpers to a handler. Use this when a handler needs a less common helper.
func (*Handler) AddHelpers ¶
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 ¶
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) 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 ¶
SendStatus writes the passed in status to the response without any data
func (*Handler) SetETag ¶
func (h *Handler) SetETag(val interface{})
SetETag sets the etag with the md5 value
func (*Handler) SetExpires ¶
SetExpires sets the Expires response header with a properly formatted time value
func (*Handler) SetExpiresIn ¶
SetExpiresIn is a helper to simplify the calling of SetExpires
func (*Handler) SetFlash ¶
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) SetLastModified ¶
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 ¶
ToJSONWithStatus json encodes an interface into the response writer with a custom http status code
func (*Handler) ValidateOrigin ¶
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 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 (*Route) Matches ¶
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 ¶
MatchesPath checks for path matches and allows for wildcards
type ServerError ¶
type Store ¶
type Store struct {
TableName string
}
Store is the include common attrs and methods for other *model types
func (Store) Create ¶
func (s Store) Create(c context.Context, data interface{}, parentKey *datastore.Key) (*datastore.Key, error)
Create creates the model