server

package
v0.0.0-...-2ddd709 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2024 License: BSD-3-Clause Imports: 29 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EchoContext

func EchoContext(ctx context.Context, c echo.Context) context.Context

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

func EchoForContext(ctx context.Context) echo.Context

EchoForContext pulls echo.Context value for context

func Middleware

func Middleware(server *Server) echo.MiddlewareFunc

Middleware will add the provided *Server instance to the context

func ServerContext

func ServerContext(ctx context.Context, server *Server) context.Context

Context adds user object to context for immediate use

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

type Context struct {
	echo.Context
	Server *Server
	User   gobwebs.User
}

Context is the context passed to handlers and middlewares

func (*Context) Error

func (c *Context) Error(err 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

func (c *Context) NewTemplate(tfs fs.FS, filenames ...string) (*template.Template, error)

NewTemplate will return a new template.Template instance based on the current templateBase (see validate.Template)

func (*Context) Render

func (c *Context) Render(code int, name string, data interface{}) (err error)

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

func (*Context) RenderTemplate

func (c *Context) RenderTemplate(
	tmpl *template.Template, code int, name string, data interface{}) (err error)

RenderTemplate is like Render except it accepts a *template.Template instance to render from.

type Extension

type Extension interface {
	Extend(gserver *Server) (*Server, error)
}

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

func ForContext(ctx context.Context) *Server

ForContext pulls user value for context

func New

func New(e *echo.Echo, db *sql.DB, c *config.Config) *Server

New creates a new server instance

func (*Server) AddFuncs

func (s *Server) AddFuncs(funcs template.FuncMap)

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

func (s *Server) AddStaticVar(key string, value any) error

AddStaticVar adds a static variable to the template renderer context

func (*Server) AppInfo

func (s *Server) AppInfo() string

AppInfo returns a string in format: `<name> <version>`

func (*Server) CSRFAddSkip

func (s *Server) CSRFAddSkip(routes ...string)

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

func (s *Server) Extend(ext Extension) (*Server, error)

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

func (s *Server) HTTPErrorHandler(err error, c echo.Context)

HTTPErrorHandler custom error handler for entire app

func (*Server) Initialize

func (s *Server) Initialize() *Server

Initialize loads the echo environments

func (*Server) LoadTemplates

func (s *Server) LoadTemplates(paths ...string) error

LoadTemplates will add to the existing template mapping

func (*Server) LoadTemplatesFS

func (s *Server) LoadTemplatesFS(tfs fs.FS, paths ...string) error

LoadTemplatesFS will add to the existing template mapping

func (*Server) LogErrorFunc

func (s *Server) LogErrorFunc(c echo.Context, err error, stack []byte) error

LogErrorFunc will handle logging the stack trace for an error

func (*Server) Logger

func (s *Server) Logger() echo.Logger

Logger returns this server's logger.

func (*Server) QueueTask

func (s *Server) QueueTask(qname string, task *work.Task) error

QueueTask will add a task to a specific queue. Queue should be identified by queue name.

func (*Server) Run

func (s *Server) Run()

Run will run the server

func (*Server) SetQueueTimeout

func (s *Server) SetQueueTimeout(d time.Duration)

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

func (s *Server) TemplateAllowOverride(keys ...string)

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

func (s *Server) TemplateProtectVariables(protect bool)

TemplateProtectVariables will set whether or not to protect variable name collisions from handler Map data.

func (*Server) WithAppInfo

func (s *Server) WithAppInfo(name, version string) *Server

WithAppInfo sets the application name and version

func (*Server) WithCertManager

func (s *Server) WithCertManager(cm *autocert.Manager) *Server

WithCertManager adds an autocert.Manager to be used for auto TLS

func (*Server) WithDefaultMiddleware

func (s *Server) WithDefaultMiddleware() *Server

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

func (s *Server) WithMiddleware(middlewares ...echo.MiddlewareFunc) *Server

WithMiddleware add user-defined middleware to the server

func (*Server) WithQueues

func (s *Server) WithQueues(queues ...*work.Queue) *Server

WithQueues add dowork task queues for this server to manage

func (*Server) WithStorage

func (s *Server) WithStorage(svc storage.Service) *Server

WithStorage sets the email ServiceQueue instance

func (*Server) WorkQueues

func (s *Server) WorkQueues() []*work.Queue

WorkQueues returns the `queues` slice

Jump to

Keyboard shortcuts

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