Documentation ¶
Index ¶
- func EchoContext(ctx context.Context, c echo.Context) context.Context
- func EchoForContext(ctx context.Context) echo.Context
- func Middleware(server *Server) echo.MiddlewareFunc
- func ServerContext(ctx context.Context, server *Server) context.Context
- type BaseService
- type Context
- func (c *Context) Error(err error)
- func (c *Context) NewTemplate(tfs fs.FS, filenames ...string) (*template.Template, error)
- func (c *Context) Render(code int, name string, data interface{}) (err error)
- func (c *Context) RenderTemplate(tmpl *template.Template, code int, name string, data interface{}) (err error)
- type Extension
- type MiddlewareConfig
- type Server
- func (s *Server) AddFuncs(funcs template.FuncMap)
- func (s *Server) AddStaticFunc(fs ...validate.StaticFunc)
- func (s *Server) AddStaticVar(key string, value any) error
- func (s *Server) AppInfo() string
- func (s *Server) CSRFAddSkip(routes ...string)
- func (s *Server) DefaultMiddlewareWithConfig(conf *MiddlewareConfig) *Server
- func (s *Server) Echo() *echo.Echo
- func (s *Server) Extend(ext Extension) (*Server, error)
- func (s *Server) GetSessionManager() *scs.SessionManager
- func (s *Server) HTTPErrorHandler(err error, c echo.Context)
- func (s *Server) Initialize() *Server
- func (s *Server) LoadTemplates(paths ...string) error
- func (s *Server) LoadTemplatesFS(tfs fs.FS, paths ...string) error
- func (s *Server) LogErrorFunc(c echo.Context, err error, stack []byte) error
- func (s *Server) Logger() echo.Logger
- func (s *Server) QueueTask(qname string, task *work.Task) error
- func (s *Server) Run()
- func (s *Server) SetQueueTimeout(d time.Duration)
- func (s *Server) Shutdown()
- func (s *Server) TemplateAllowOverride(keys ...string)
- func (s *Server) TemplateProtectVariables(protect bool)
- func (s *Server) WithAppInfo(name, version string) *Server
- func (s *Server) WithCertManager(cm *autocert.Manager) *Server
- func (s *Server) WithDefaultMiddleware() *Server
- func (s *Server) WithEmail(svc *email.ServiceQueue) *Server
- func (s *Server) WithMiddleware(middlewares ...echo.MiddlewareFunc) *Server
- func (s *Server) WithQueues(queues ...*work.Queue) *Server
- func (s *Server) WithStorage(svc storage.Service) *Server
- func (s *Server) WorkQueues() []*work.Queue
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EchoContext ¶
EchoContext adds the current requests echo.Context instance to the request context.Context. This is a total hack to get around the current gobwebs design of using server.Context.User (maybe should rethink this design all together)
func EchoForContext ¶
EchoForContext pulls echo.Context value for context
Types ¶
type BaseService ¶
type BaseService struct { Name string Group *echo.Group RenderFunc validate.TemplateRenderFunc }
BaseService is can be used as the base for a WebService interface
func NewService ¶
func NewService(eg *echo.Group, name string, render validate.TemplateRenderFunc) BaseService
func (*BaseService) RegisterRoutes ¶
func (b *BaseService) RegisterRoutes()
func (*BaseService) Render ¶
func (b *BaseService) Render(c echo.Context, code int, name string, data interface{}) error
func (*BaseService) RouteName ¶
func (b *BaseService) RouteName(value string) string
type Context ¶
Context is the context passed to handlers and middlewares
func (*Context) Error ¶
Error is needed because otherwise it will send an instance of *echo.context, and we want the user info, etc. from the gobwebs Context struct
func (*Context) NewTemplate ¶
NewTemplate will return a new template.Template instance based on the current templateBase (see validate.Template)
func (*Context) Render ¶
Render is a wrapper for the echo.Context.Render method. The purpose of this is to provide *server.Context to dynamic template functions. To use this, you need to type assert to *server.Context in your handler and call the render directly on the resulting context, not on the echo.Context
type Extension ¶
Extension is an interface to add on to the Server instance via a 3rd party module
type MiddlewareConfig ¶
type MiddlewareConfig struct { Sessions bool // GetSessionManager should be used to customize the values of the // scs.SessionManager instance. A function was chosen because of the // various options it supports. This makes it easier for others to // integrate their specific needs versus a large type with a ton of // flags that we would have to parse through. GetSessionManager func(srv *Server) *scs.SessionManager // If true then the session expirey date (note, this is NOT the cookie // expiry date) is extended by the default session lifetime amount from // time.Now() SessionTimeout bool ServerContext bool }
MiddlewareConfig is a config struct to set default middlewares
type Server ¶
type Server struct { Config *config.Config DB *sql.DB Session *scs.SessionManager Email *email.ServiceQueue Storage storage.Service // contains filtered or unexported fields }
Server is the global echo application server
func ForContext ¶
ForContext pulls user value for context
func New ¶
New creates a new server instance
func (*Server) AddFuncs ¶
AddFuncs functions to the global template function map
func (*Server) AddStaticFunc ¶
func (s *Server) AddStaticFunc(fs ...validate.StaticFunc)
AddStaticFunc adds a static function to the template renderer context
func (*Server) AddStaticVar ¶
AddStaticVar adds a static variable to the template renderer context
func (*Server) AppInfo ¶
AppInfo returns a string in format: `<name> <version>`
func (*Server) CSRFAddSkip ¶
CSRFAddSkip adds a route that is allowed to skip CSRF protection
func (*Server) DefaultMiddlewareWithConfig ¶
func (s *Server) DefaultMiddlewareWithConfig(conf *MiddlewareConfig) *Server
DefaultMiddlewareWithConfig sets default middleware for the application
func (*Server) Echo ¶
func (s *Server) Echo() *echo.Echo
Echo returns the servers *echo.Echo instance
func (*Server) Extend ¶
Extend will apply the given Extension interface
func (*Server) GetSessionManager ¶
func (s *Server) GetSessionManager() *scs.SessionManager
GetSessionManager returns the default configured session. To customize this session please see `MiddlewareConfig.GetSessionManager`
func (*Server) HTTPErrorHandler ¶
HTTPErrorHandler custom error handler for entire app
func (*Server) Initialize ¶
Initialize loads the echo environments
func (*Server) LoadTemplates ¶
LoadTemplates will add to the existing template mapping
func (*Server) LoadTemplatesFS ¶
LoadTemplatesFS will add to the existing template mapping
func (*Server) LogErrorFunc ¶
LogErrorFunc will handle logging the stack trace for an error
func (*Server) QueueTask ¶
QueueTask will add a task to a specific queue. Queue should be identified by queue name.
func (*Server) SetQueueTimeout ¶
SetQueueTimeout will set the timeout duration to use when waiting for queues to shutdown
func (*Server) Shutdown ¶
func (s *Server) Shutdown()
Shutdown will close echo server and work queues
func (*Server) TemplateAllowOverride ¶
TemplateAllowOverride adds template map keys values that can be overridden by handlers. For instance, if a static func sets a template Map value of "seoData", your handlers can override that value if set to be allowed.
func (*Server) TemplateProtectVariables ¶
TemplateProtectVariables will set whether or not to protect variable name collisions from handler Map data.
func (*Server) WithAppInfo ¶
WithAppInfo sets the application name and version
func (*Server) WithCertManager ¶
WithCertManager adds an autocert.Manager to be used for auto TLS
func (*Server) WithDefaultMiddleware ¶
WithDefaultMiddleware sets default middleware for the application
func (*Server) WithEmail ¶
func (s *Server) WithEmail(svc *email.ServiceQueue) *Server
WithEmail sets the email ServiceQueue instance
func (*Server) WithMiddleware ¶
WithMiddleware add user-defined middleware to the server
func (*Server) WithQueues ¶
WithQueues add dowork task queues for this server to manage
func (*Server) WithStorage ¶
WithStorage sets the email ServiceQueue instance