Documentation ¶
Index ¶
- Constants
- Variables
- func RegisterPluginLoader(f PluginLoaderFunc)
- type AuthError
- type BaseRenderData
- type Context
- type DialIMAPFunc
- type DialSMTPFunc
- type GlobalRenderData
- type GoPlugin
- func (p *GoPlugin) AddRoute(method, path string, handler HandlerFunc)
- func (p *GoPlugin) DELETE(path string, handler HandlerFunc)
- func (p *GoPlugin) GET(path string, handler HandlerFunc)
- func (p *GoPlugin) Inject(name string, f InjectFunc)
- func (p *GoPlugin) Loader() PluginLoaderFunc
- func (p *GoPlugin) POST(path string, handler HandlerFunc)
- func (p *GoPlugin) PUT(path string, handler HandlerFunc)
- func (p *GoPlugin) Plugin() Plugin
- func (p *GoPlugin) TemplateFuncs(funcs template.FuncMap)
- type HandlerFunc
- type InjectFunc
- type NoUpstreamError
- type Options
- type Plugin
- type PluginLoaderFunc
- type RenderData
- type Server
- type Session
- type SessionManager
- type Store
Constants ¶
const PluginDir = "plugins"
PluginDir is the path to the plugins directory.
Variables ¶
var ErrNoStoreEntry = fmt.Errorf("koushin: no such entry in store")
ErrNoStoreEntry is returned by Store.Get when the entry doesn't exist.
Functions ¶
func RegisterPluginLoader ¶
func RegisterPluginLoader(f PluginLoaderFunc)
RegisterPluginLoader registers a plugin loader. The loader will be called on server start-up and reload.
Types ¶
type AuthError ¶
type AuthError struct {
// contains filtered or unexported fields
}
AuthError wraps an authentication error.
type BaseRenderData ¶
type BaseRenderData struct { GlobalData GlobalRenderData // additional plugin-specific data Extra map[string]interface{} }
BaseRenderData is the base type for templates. It should be extended with additional template-specific fields:
type MyRenderData struct { BaseRenderData // add additional fields here }
func NewBaseRenderData ¶
func NewBaseRenderData(ctx *Context) *BaseRenderData
NewBaseRenderData initializes a new BaseRenderData.
It can be used by routes to pre-fill the base data:
type MyRenderData struct { BaseRenderData // add additional fields here } data := &MyRenderData{ BaseRenderData: *koushin.NewBaseRenderData(ctx), // other fields... }
func (*BaseRenderData) Global ¶
func (brd *BaseRenderData) Global() *GlobalRenderData
Global implements RenderData.
type Context ¶
Context is the context used by HTTP handlers.
Use a type assertion to get it from a echo.Context:
ctx := ectx.(*koushin.Context)
func (*Context) SetSession ¶
SetSession sets a cookie for the provided session. Passing a nil session unsets the cookie.
type DialIMAPFunc ¶
type DialIMAPFunc func() (*imapclient.Client, error)
DialIMAPFunc connects to the upstream IMAP server.
type DialSMTPFunc ¶
type DialSMTPFunc func() (*smtp.Client, error)
DialSMTPFunc connects to the upstream SMTP server.
type GlobalRenderData ¶
type GlobalRenderData struct { Path string LoggedIn bool // if logged in Username string // additional plugin-specific data Extra map[string]interface{} }
GlobalRenderData contains data available in all templates.
type GoPlugin ¶
type GoPlugin struct { Name string // contains filtered or unexported fields }
GoPlugin is a helper to create Go plugins.
Use this struct to define your plugin, then call RegisterPluginLoader:
p := GoPlugin{Name: "my-plugin"} // Define routes, template functions, etc koushin.RegisterPluginLoader(p.Loader())
func (*GoPlugin) AddRoute ¶
func (p *GoPlugin) AddRoute(method, path string, handler HandlerFunc)
AddRoute registers a new HTTP route.
func (*GoPlugin) DELETE ¶
func (p *GoPlugin) DELETE(path string, handler HandlerFunc)
func (*GoPlugin) GET ¶
func (p *GoPlugin) GET(path string, handler HandlerFunc)
func (*GoPlugin) Inject ¶
func (p *GoPlugin) Inject(name string, f InjectFunc)
Inject registers a function to execute prior to rendering a template. The special name "*" matches any template.
func (*GoPlugin) Loader ¶
func (p *GoPlugin) Loader() PluginLoaderFunc
Loader returns a loader function for this plugin.
func (*GoPlugin) POST ¶
func (p *GoPlugin) POST(path string, handler HandlerFunc)
func (*GoPlugin) PUT ¶
func (p *GoPlugin) PUT(path string, handler HandlerFunc)
func (*GoPlugin) TemplateFuncs ¶
TemplateFuncs registers new template functions.
type HandlerFunc ¶
HandlerFunc is a function serving HTTP requests.
type InjectFunc ¶
type InjectFunc func(ctx *Context, data RenderData) error
InjectFunc is a function that injects data prior to rendering a template.
type NoUpstreamError ¶
type NoUpstreamError struct {
// contains filtered or unexported fields
}
func (*NoUpstreamError) Error ¶
func (err *NoUpstreamError) Error() string
type Plugin ¶
type Plugin interface { // Name should return the plugin name. Name() string // LoadTemplate populates t with the plugin's functions and templates. LoadTemplate(t *template.Template) error // SetRoutes populates group with the plugin's routes. SetRoutes(group *echo.Group) // Inject is called prior to rendering a template. It can extend the // template data by setting new items in the Extra map. Inject(ctx *Context, name string, data RenderData) error // Close is called when the plugin is unloaded. Close() error }
Plugin extends koushin with additional functionality.
type PluginLoaderFunc ¶
PluginLoaderFunc loads plugins for the provided server.
type RenderData ¶
type RenderData interface { // GlobalData returns a pointer to the global render data. Global() *GlobalRenderData }
RenderData is implemented by template data structs. It can be used to inject additional data to all templates.
type Server ¶
type Server struct { Sessions *SessionManager // contains filtered or unexported fields }
Server holds all the koushin server state.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session is an active user session. It may also hold an IMAP connection.
The session's password is not available to plugins. Plugins should use the session helpers to authenticate outgoing connections, for instance DoSMTP.
func (*Session) Close ¶
func (s *Session) Close()
Close destroys the session. This can be used to log the user out.
func (*Session) DoIMAP ¶
func (s *Session) DoIMAP(f func(*imapclient.Client) error) error
DoIMAP executes an IMAP operation on this session. The IMAP client can only be used from inside f.
func (*Session) DoSMTP ¶
DoSMTP executes an SMTP operation on this session. The SMTP client can only be used from inside f.
func (*Session) SetHTTPBasicAuth ¶
SetHTTPBasicAuth adds an Authorization header field to the request with this session's credentials.
type SessionManager ¶
type SessionManager struct {
// contains filtered or unexported fields
}
SessionManager keeps track of active sessions. It connects and re-connects to the upstream IMAP server as necessary. It prunes expired sessions.