server

package
v0.0.0-...-4ee5816 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2023 License: BSD-3-Clause Imports: 38 Imported by: 2

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 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) 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

type GraphQL

type GraphQL struct {
	Schema        graphql.ExecutableSchema
	MaxComplexity int
	MaxUploadSize int
}

GraphQL is a holder for a graphql schema and options

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
	GQL     *GraphQL
	// 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) 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) 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) WithSchema

func (s *Server) WithSchema(
	schema graphql.ExecutableSchema, scopes []string) *Server

WithSchema Adds a GraphQL schema for this server. The second parameter shall be the list of scopes, as strings, which are supported by this schema. This function configures routes for the router; all middlewares must be configured before this is called.

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