app

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: May 10, 2023 License: BSD-1-Clause Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cache

func Cache() client.Cache

func Database added in v1.6.2

func Database() *sql.DB

func Filer added in v1.6.2

func Filer() fs.Filer

func Flags

func Flags() *flag.Flags

func LoggerMiddleware

func LoggerMiddleware(l request.Logger) router.Middleware

func Mailer

func Mailer() *email.Manager

func Templates

func Templates() *templates.Manager

Types

type Application

type Application struct {
	// Wether the application is in debug mode.
	DEBUG bool

	// The secret key for the application.
	// This is used to encrypt, decrypt, and sign data.
	SecretKey secret.Key

	Router *router.Router
	Logger request.Logger

	Auth *auth.AuthApp
	// contains filtered or unexported fields
}

Application is the main application object.

This is used to store all the application data.

func App

func App() *Application

Returns the application object after it has been initialized.

func New

func New(c Config) *Application

Initialize a new application.

This will set up the database, sessionmanager and other things.

This is also where to register extra command-line flags.

func (*Application) Cache

func (a *Application) Cache() client.Cache

func (*Application) Database added in v1.6.2

func (a *Application) Database() *sql.DB

func (*Application) Filer added in v1.6.2

func (a *Application) Filer() fs.Filer

func (*Application) Flags

func (a *Application) Flags() *flag.Flags

Application flags.

These are flags which can be added to the application.

They exist to centralize the flags used by the application, and possibly other packages.

func (*Application) Mailer

func (a *Application) Mailer() *email.Manager

func (*Application) Middlewares

func (a *Application) Middlewares(m ...router.Middleware)

Add a middleware to the router.

func (*Application) Redirect

func (a *Application) Redirect() error

Set up a redirect server to redirect all HTTP requests to HTTPS.

This is only used if the SSL config is set to true.

func (*Application) Run

func (a *Application) Run() error

Run the application.

This will start the server and listen for requests.

If the server is running in SSL mode, this will also start a redirect server.

func (*Application) Serve

func (a *Application) Serve() (http.Handler, error)

Instead of running the application, retrieve the handler/serve mux.

func (*Application) TemplateFuncs

func (a *Application) TemplateFuncs(t template.FuncMap)

Add functions to the template.

func (*Application) Templates

func (a *Application) Templates() *templates.Manager

type Config

type Config struct {
	// Loglevel to use.
	// If not specified, the default loglevel will be used.
	LogLevel logger.Loglevel

	// The hostnames that are allowed to access the application.
	AllowedHosts []string

	// Options for the rate limiter.
	// If not specified, the rate limiter will not be used.
	RateLimitOptions *middleware.RateLimitOptions

	// The secret key for the application.
	SecretKey string

	// The HTTP server configuration.
	Server         *Server
	RedirectServer *RedirectServer

	// The application's cache.
	Cache client.Cache

	// Force the application to use a cache.
	//
	// If an error occurs connecting to the cache, do not proceed.
	ForceCache bool

	// Email settings:
	// Timeout to wait for a response from the server
	// Errors if the timeout is reached.
	// TLS Config to use when USE_SSL is true.
	// Default smpt authentication method
	// Hook for when an email will be sent
	Mail *email.Manager

	// Size of the file queue
	// Hook for when a file is read, or written in the media directory.
	File fs.Filer

	// The session store to use.
	SessionStore scs.Store

	// Use template cache?
	// Template cache to use, if enabled
	// Default base template suffixes
	// Default directory to look in for base templates
	// Functions to add to templates
	// Template file system
	//
	//	USE_TEMPLATE_CACHE bool
	//	BASE_TEMPLATE_SUFFIXES []string
	//	BASE_TEMPLATE_DIRS []string
	//	TEMPLATE_DIRS      []string
	//	DEFAULT_FUNCS template.FuncMap
	//	TEMPLATEFS fs.FS
	Templates *templates.Manager

	// The database to use.
	Database *sql.DB

	// Use authentication?
	DisableAuthentication bool

	Middlewares          []router.Middleware
	DefaultTemplateFuncs template.FuncMap

	// DefaultFlags are the default flags that will be added to the application.
	// You can add more flags by using the Application.Flags().Register() function.
	DefaultFlags []*flag.Command

	// Default error handler on panics.
	ErrorHandler func(error, *request.Request)
}

Config is the configuration used to initialize the application. You must provide a server configuration!

type RedirectServer

type RedirectServer struct {
	Host       string
	Port       int
	URL        string
	StatusCode int
}

RedirectServer is the configuration used to initialize the redirect server. This will only be used if the server is running in SSL mode.

type Server

type Server struct {
	// The address to listen on
	Host string
	Port int
	// Wether to skip trailing slashes
	SkipTrailingSlash bool
	// The server to use
	Server *http.Server
	// The handler to use when a route is not found
	NotFoundHandler router.Handler
	// SSL options
	CertFile string
	KeyFile  string
}

Server is the configuration used to initialize the server.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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