Documentation ¶
Index ¶
- Constants
- Variables
- func DefaultEngine(a *App) error
- func NewStaticor(env *Env) *staticor
- func NewTemplator(env *Env) *templator
- type App
- func (app *App) Blueprints() []*Blueprint
- func (a *App) Configure(c ...Configuration) error
- func (app *App) MergeRoutes(blueprint *Blueprint, routes Routes)
- func (app *App) Mount(mount string, inherit bool, blueprints ...*Blueprint) error
- func (app *App) Name() string
- func (app *App) RegisterBlueprints(blueprints ...*Blueprint)
- func (app *App) Routes() Routes
- func (app *App) Run(addr string)
- type AssetDirectory
- type AssetFS
- type AssetFile
- type Assets
- type Blueprint
- func (b *Blueprint) CtxProcessor(name string, fn interface{})
- func (b *Blueprint) CtxProcessors(cp map[string]interface{})
- func (b *Blueprint) DELETE(path string, handlers ...HandlerFunc)
- func (b *Blueprint) GET(path string, handlers ...HandlerFunc)
- func (b *Blueprint) HEAD(path string, handlers ...HandlerFunc)
- func (b *Blueprint) Handle(route *Route)
- func (b *Blueprint) NewBlueprint(component string, handlers ...HandlerFunc) *Blueprint
- func (b *Blueprint) OPTIONS(path string, handlers ...HandlerFunc)
- func (b *Blueprint) PATCH(path string, handlers ...HandlerFunc)
- func (b *Blueprint) POST(path string, handlers ...HandlerFunc)
- func (b *Blueprint) PUT(path string, handlers ...HandlerFunc)
- func (b *Blueprint) Register(a *App)
- func (b *Blueprint) STATIC(path string)
- func (b *Blueprint) StatusHandle(code int, handlers ...HandlerFunc)
- func (b *Blueprint) Use(handlers ...HandlerFunc)
- func (b *Blueprint) UseAt(index int, handlers ...HandlerFunc)
- type Config
- type Configuration
- func CtxFunc(name string, fn interface{}) Configuration
- func CtxFuncs(fns map[string]interface{}) Configuration
- func CtxProcessor(name string, fn interface{}) Configuration
- func CtxProcessors(fns map[string]interface{}) Configuration
- func EnvItem(items ...string) Configuration
- func Mode(mode string, value bool) Configuration
- func TemplateFunction(name string, fn interface{}) Configuration
- func TemplateFunctions(fns map[string]interface{}) Configuration
- func Templating(t Templator) Configuration
- type Ctx
- func (ctx *Ctx) Abort(code int)
- func (ctx *Ctx) AllFlashMessages() map[string]string
- func (ctx *Ctx) Call(name string, args ...interface{}) (interface{}, error)
- func (ctx *Ctx) Cookie(name string, value string, opts ...interface{}) error
- func (ctx *Ctx) Cookies() map[string]*http.Cookie
- func (ctx *Ctx) Copy() *Ctx
- func (ctx *Ctx) Flash(category string, message string)
- func (ctx *Ctx) FlashMessages(categories ...string) []string
- func (ctx *Ctx) Get(key string) (interface{}, error)
- func (ctx *Ctx) ModifyHeader(action string, values ...[]string)
- func (ctx *Ctx) Next()
- func (ctx *Ctx) Push(fn HandlerFunc)
- func (ctx *Ctx) ReadCookies() map[string]string
- func (ctx *Ctx) Redirect(code int, location string)
- func (ctx *Ctx) Release()
- func (ctx *Ctx) RenderTemplate(name string, data interface{})
- func (ctx *Ctx) SecureCookie(name string, value string, opts ...interface{}) error
- func (ctx *Ctx) ServeFile(f http.File)
- func (ctx *Ctx) ServePlain(code int, data []byte)
- func (ctx *Ctx) Set(key string, item interface{})
- func (ctx *Ctx) Start()
- func (ctx *Ctx) Status(code int)
- func (ctx *Ctx) UrlExternal(route string, params ...string) string
- func (ctx *Ctx) UrlRelative(route string, params ...string) string
- func (ctx *Ctx) WriteToHeader(code int, values ...[]string)
- type Current
- type Engine
- type Env
- func (env *Env) AddCtxFunc(name string, fn interface{}) error
- func (env *Env) AddCtxFuncs(fns map[string]interface{}) error
- func (env *Env) AddTplFunc(name string, fn interface{})
- func (env *Env) AddTplFuncs(fns map[string]interface{})
- func (env *Env) BaseEnv()
- func (env *Env) MergeEnv(other *Env)
- func (env *Env) MergeStore(other Store)
- func (env *Env) SessionInit()
- func (env *Env) SetMode(mode string, value bool) error
- func (env *Env) StaticDirs(dirs ...string) []string
- func (env *Env) StaticorInit()
- func (env *Env) TemplateDirs(dirs ...string) []string
- func (env *Env) TemplatorInit()
- type FakeFile
- type FlotillaError
- type HandlerFunc
- type Loader
- type Modes
- type ResponseWriter
- type Route
- type Routes
- type SetEngine
- type Staticor
- type Store
- type StoreItem
- type TData
- type Templator
Constants ¶
const ( ErrorTypeInternal = 1 << iota ErrorTypeExternal = 1 << iota ErrorTypeAll = 0xffffffff )
Variables ¶
var (
FlotillaPath string
)
Functions ¶
func DefaultEngine ¶
func NewStaticor ¶
func NewStaticor(env *Env) *staticor
func NewTemplator ¶
func NewTemplator(env *Env) *templator
NewTemplator returns a new instance of the default Flotilla templator.
Types ¶
type App ¶
The base of running a Flotilla instance is an App struct with a Name, an Env with information specific to running the App, and a chain of Blueprints
func New ¶
func New(name string, enginefn SetEngine, conf ...Configuration) *App
Returns a new App with the provided Engine and minimum configuration.
func (*App) Blueprints ¶
Blueprints provides a flat array of Blueprint instances attached to the App.
func (*App) Configure ¶
func (a *App) Configure(c ...Configuration) error
Configure takes any number of Configuration functions and to run the app through.
func (*App) MergeRoutes ¶
MergeRoutes merges the given blueprint with the given routes, by route existence.
func (*App) Mount ¶
Mount takes an unregistered blueprint, registering and mounting the routes to the provided string mount point with a copy of the blueprint. If inherit is true, the blueprint becomes a child blueprint of app.Blueprint.
func (*App) RegisterBlueprints ¶
RegisterBlueprints integrates the given blueprints with the App.
type AssetDirectory ¶
func NewAssetDirectory ¶
func NewAssetDirectory(name string, children []string, fs *AssetFS) *AssetDirectory
type AssetFS ¶
type AssetFS struct { Asset func(string) ([]byte, error) AssetDir func(string) ([]string, error) AssetNames func() []string Prefix string }
A pseudo-file structure constructed from functions & optional prefix Flotilla can use binary data, and is the current optimal way to define inbuilt assets for extensions. See: https://github.com/jteeuwen/go-bindata https://github.com/elazarl/go-bindata-assetfs
type AssetFile ¶
func NewAssetFile ¶
type Assets ¶
type Assets []*AssetFS
An array of AssetFS instances
type Blueprint ¶
type Blueprint struct { Prefix string Handlers []HandlerFunc // contains filtered or unexported fields }
A Blueprint gathers any number routes around a prefix and an array of group specific handlers.
func NewBlueprint ¶
NewBlueprint returns a new Blueprint with the provided string prefix.
func (*Blueprint) CtxProcessor ¶
CtxProcessors takes a name string and an interface to add a ContextProcessor to the blueprint.
func (*Blueprint) CtxProcessors ¶
CtxProcessors takes a map of ContextProcessors keyed by string for the blueprint.
func (*Blueprint) DELETE ¶
func (b *Blueprint) DELETE(path string, handlers ...HandlerFunc)
func (*Blueprint) GET ¶
func (b *Blueprint) GET(path string, handlers ...HandlerFunc)
func (*Blueprint) HEAD ¶
func (b *Blueprint) HEAD(path string, handlers ...HandlerFunc)
func (*Blueprint) Handle ¶
Handle registers new handlers and/or existing handlers with a constructed Route. For GET, POST, DELETE, PATCH, PUT, OPTIONS, and HEAD requests the respective shortcut functions can be used by specifying path & handlers.
func (*Blueprint) NewBlueprint ¶
func (b *Blueprint) NewBlueprint(component string, handlers ...HandlerFunc) *Blueprint
New creates a new child Blueprint from the existing Blueprint.
func (*Blueprint) OPTIONS ¶
func (b *Blueprint) OPTIONS(path string, handlers ...HandlerFunc)
func (*Blueprint) PATCH ¶
func (b *Blueprint) PATCH(path string, handlers ...HandlerFunc)
func (*Blueprint) POST ¶
func (b *Blueprint) POST(path string, handlers ...HandlerFunc)
func (*Blueprint) PUT ¶
func (b *Blueprint) PUT(path string, handlers ...HandlerFunc)
func (*Blueprint) Register ¶
Register will provide the app instance to the blueprint to finalize all deferred actions.
func (*Blueprint) STATIC ¶
STATIC adds a Static route handled by the app, based on the blueprint prefix.
func (*Blueprint) StatusHandle ¶
func (b *Blueprint) StatusHandle(code int, handlers ...HandlerFunc)
Custom HttpStatus for the group, set and called from engine HttpStatuses
func (*Blueprint) Use ¶
func (b *Blueprint) Use(handlers ...HandlerFunc)
Use adds any number of HandlerFunc to the Blueprint which will be run before route handlers for all Route attached to the Blueprint.
func (*Blueprint) UseAt ¶
func (b *Blueprint) UseAt(index int, handlers ...HandlerFunc)
UseAt adds any number of HandlerFunc to the Blueprint at the given index, for when you must control the position in relation to other middleware.
type Config ¶
type Config struct { Configured bool Configuration []Configuration // contains filtered or unexported fields }
type Configuration ¶
A function that takes an App pointer to configure the App.
func CtxFunc ¶
func CtxFunc(name string, fn interface{}) Configuration
CtxFunc adds a single function accessible as a Context Function.
func CtxFuncs ¶
func CtxFuncs(fns map[string]interface{}) Configuration
CtxFuncs adds a map of functions accessible as Context Functions.
func CtxProcessor ¶
func CtxProcessor(name string, fn interface{}) Configuration
CtxProcessor adds a single template context processor to the App primary Blueprint. This will affect all Blueprints & Routes.
func CtxProcessors ¶
func CtxProcessors(fns map[string]interface{}) Configuration
CtxProcessors adds a map of context processors to the App primary Blueprint.
func EnvItem ¶
func EnvItem(items ...string) Configuration
EnvItem adds strings of the form "section_label:value" or "label:value" to the Env store, bypassing and without reading a conf file.
func Mode ¶
func Mode(mode string, value bool) Configuration
Mode takes a string for development, production, or testing to set the App mode.
func TemplateFunction ¶
func TemplateFunction(name string, fn interface{}) Configuration
TemplateFunction passes a template function to the env for Templator use.
func TemplateFunctions ¶
func TemplateFunctions(fns map[string]interface{}) Configuration
TemplateFunction passes a map of functions to the env for Templator use.
func Templating ¶
func Templating(t Templator) Configuration
Templating supplies a Templator to the App.
type Ctx ¶
type Ctx struct { Request *http.Request Session session.SessionStore Data map[string]interface{} App *App // contains filtered or unexported fields }
Ctx is the primary context for passing & setting data between handlerfunc of a route, constructed from the *App and the app engine context data.
func (*Ctx) AllFlashMessages ¶
AllFlashMessages gets all flash messages set in the session.
func (*Ctx) Cookie ¶
Cookie takes a name, value and optional options(MaxAge as int, Path & Domain as string, Secure & as bool) to add a cookie to the header.
func (*Ctx) FlashMessages ¶
FlashMessages gets flash messages set in the session by provided categories.
func (*Ctx) ModifyHeader ¶
func (*Ctx) Next ¶
func (ctx *Ctx) Next()
Executes the pending handlers in the chain inside the calling handlectx.
func (*Ctx) Push ¶
func (ctx *Ctx) Push(fn HandlerFunc)
Push places a handlerfunc in ctx.deferred for execution after all handlersfuncs have run.
func (*Ctx) ReadCookies ¶
func (*Ctx) Redirect ¶
Returns a HTTP redirect to the specific location, with the specified code. using the Ctx redirect function.
func (*Ctx) RenderTemplate ¶
RenderTemplate renders an HTML template response with the Ctx rendertemplate function.
func (*Ctx) SecureCookie ¶
func (*Ctx) ServePlain ¶
ServePlain writes plain data into the body stream and updates the HTTP code, using the Ctx serveplain function.
func (*Ctx) UrlExternal ¶
Provides a full, external url for the route specified using the given parameters, using the Ctx urlfor function.
func (*Ctx) UrlRelative ¶
Provides a relative url for the route specified using the parameters specified, using the Ctx urlfor function.
func (*Ctx) WriteToHeader ¶
WriteToHeader writes the specified code and values to the response Head. values are 2 string arrays indicating the key first and the value second to set in the Head.
type Current ¶
type Current interface { Request() *http.Request Data() map[string]interface{} Form() url.Values Files() map[string][]*multipart.FileHeader StatusFunc() (func(int), bool) Writer() engine.ResponseWriter }
The Current interface handles the information boundary between incoming engine context and flotilla context. The engine must provide a context.Context with a Value fitting this interface.
type Env ¶
type Env struct { Mode *Modes Store SessionManager *session.Manager Assets Staticor Templator // contains filtered or unexported fields }
The App environment containing configuration variables & their store as well as other info & data relevant to the app.
func EmptyEnv ¶
func EmptyEnv() *Env
EmptyEnv produces an Env with intialization but no configuration.
func (*Env) AddCtxFunc ¶
AddCtxFunc adds a single Ctx function with the name string, checking that the function is a valid function returning 1 value, or 1 value and 1 error value.
func (*Env) AddCtxFuncs ¶
AddCtxFuncs stores cross-handler functions in the Env as intermediate staging for later use by Ctx.
func (*Env) AddTplFunc ¶
AddTplFuncs adds template functions stored in the Env for use by a Templator.
func (*Env) AddTplFuncs ¶
AddTplFuncs adds template functions stored in the Env for use by a Templator.
func (*Env) MergeStore ¶
MergeStore merges a Store instance with the Env's Store, without replacement.
func (*Env) SessionInit ¶
func (env *Env) SessionInit()
SessionInit initializes the session using the SessionManager, or default if no session manage is specified.
func (*Env) StaticDirs ¶
A string array of static dirs set in env.Store["staticdirectories"]
func (*Env) StaticorInit ¶
func (env *Env) StaticorInit()
func (*Env) TemplateDirs ¶
TemplateDirs produces a listing of templator template directories.
func (*Env) TemplatorInit ¶
func (env *Env) TemplatorInit()
TemplatorInit sets a default templator if one is not set, and gathers template directories from all attached Flotilla envs.
type FlotillaError ¶
type FlotillaError struct {
// contains filtered or unexported fields
}
func (*FlotillaError) Error ¶
func (e *FlotillaError) Error() string
type HandlerFunc ¶
type HandlerFunc func(*Ctx)
A HandlerFunc is any function taking a single parameter, *Ctx
type Loader ¶
type Loader struct { FileExtensions []string // contains filtered or unexported fields }
The default templator loader
func (*Loader) AssetTemplates ¶
AssetTemplates returns a string array of templates in binary assets attached to the application. Iterates all assets, returns filenames matching flotilla loader valid extensions(default .html, .dji).
func (*Loader) ListTemplates ¶
func (fl *Loader) ListTemplates() interface{}
ListTemplates returns a string array of absolute template paths for all templates dirs & assets matching valid extensions(default .html, .dji) and associated with the flotilla loader.
func (*Loader) ValidExtension ¶
type ResponseWriter ¶
type Route ¶
type Route struct { Name string // contains filtered or unexported fields }
Data about a route for use & reuse within App.
func NewRoute ¶
func NewRoute(method string, path string, static bool, handlers []HandlerFunc) *Route
NewRoute returns a new Route from a string method, a string path, a boolean indicating if the route is static, and an array of HandlerFunc
func (*Route) CtxProcessor ¶
func (*Route) CtxProcessors ¶
func (*Route) Named ¶
Named produces a default name for the route based on path & parameters, useful to Blueprint and App, where a route is not specifically named.
func (*Route) Url ¶
Url takes string parameters and applies them to a Route. First to any :parameter params, then *splat params. If any params are left over(not the case with a *splat), and the route method is GET, a query string of key=value is appended to the end of the url with arbitrarily assigned keys(e.g. value1=param) where no key is provided
e.g. r1 := NewRoute("GET", /my/:mysterious/path, false, []HandlerFunc{AHandlerFunc}) r2 := NewRoute("GET", /my/*path, false, []HandlerFunc{AHandlerFunc}) u1, _ := r1.Url("hello", "world=are" "you=there", "sayhi") u2, _ := r2.Url("hello", "world", "are" "you", "there") fmt.Printf("url1: %s\n", u1)
/my/hello/path?world=are&you=there&value3=sayhi
fmt.Printf("url2: %s\n", u2)
/my/hello/world/are/you/there
type Store ¶
Store is a map of StoreItem managed by App.Env, used as a store of varied configuration items that might be represented with a default and/or explicitly set value.
func (Store) LoadConfByte ¶
LoadConfByte loads a text configuration file as byte into a Store.
func (Store) LoadConfFile ¶
LoadConfFile loads a text configuration file into a Store.
type StoreItem ¶
type StoreItem struct { Value string // contains filtered or unexported fields }
A StoreItem contains a default string value and/or a string value.
type TData ¶
type TData map[string]interface{}
TData is a map sent to and accessible within the template, by the builtin rendertemplate function.
func TemplateData ¶
func (TData) CALL ¶
CALL will call the context processor by name, returning an interface{} or error.
func (TData) GetFlashMessages ¶
GetFlashMessages gets flash messages stored with TData by category.
func (TData) HTML ¶
HTML will call the context processor by name return html, html formatted error, or html formatted notice that the processor could not return an html value.