Documentation ¶
Index ¶
- type App
- func (a *App) AddChainedRoute(pattern string, handler http.Handler, chain route.Chain)
- func (a *App) AddChainedRoutes(routes map[string]http.Handler, chain route.Chain)
- func (a *App) AddRoute(pattern string, handler http.Handler, middleware ...route.Middleware)
- func (a *App) AddRoutes(routes map[string]http.Handler, middleware ...route.Middleware)
- func (a *App) Config() *conf.HopConfig
- func (a *App) Dispatcher() *dispatch.Dispatcher
- func (a *App) Error() error
- func (a *App) GetModule(id string) (Module, error)
- func (a *App) Logger() *slog.Logger
- func (a *App) NewResponse(r *http.Request) (*render.Response, error)
- func (a *App) NewTemplateData(r *http.Request) map[string]any
- func (a *App) OnShutdown(fn func(context.Context) error)
- func (a *App) OnTemplateData(fn OnTemplateDataFunc)
- func (a *App) RegisterModule(m Module) *App
- func (a *App) Router() *route.Mux
- func (a *App) RunInBackground(r *http.Request, fn func() error)
- func (a *App) Session() *scs.SessionManager
- func (a *App) ShutdownServer(ctx context.Context) error
- func (a *App) Start(ctx context.Context) error
- func (a *App) StartModules(ctx context.Context) error
- func (a *App) Stop(ctx context.Context) error
- func (a *App) TM() *render.TemplateManager
- type AppConfig
- type ConfigurableModule
- type DispatcherModule
- type HTTPModule
- type Module
- type OnTemplateDataFunc
- type ShutdownModule
- type StartupModule
- type TemplateDataModule
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App holds core components that most services need
func (*App) AddChainedRoute ¶
AddChainedRoute adds a new route to the server with a chain of middleware It takes a pattern, an http.Handler, and a route.Chain struct
func (*App) AddChainedRoutes ¶
AddChainedRoutes adds multiple routes to the server with a chain of middleware
func (*App) AddRoute ¶
AddRoute adds a new route to the server, using the newer v1.22 http.Handler interface. It takes a pattern, an http.Handler, and an optional list of middleware.
func (*App) AddRoutes ¶
AddRoutes adds multiple routes to the server. It takes a map of patterns to http.Handlers and an optional list of middleware.
func (*App) Dispatcher ¶ added in v0.0.22
func (a *App) Dispatcher() *dispatch.Dispatcher
Dispatcher returns the event bus for the app
func (*App) NewResponse ¶
NewResponse creates a new Response instance with the TemplateManager.
func (*App) NewTemplateData ¶
NewTemplateData returns a map of data that can be used in a Go template, API response, etc. It includes the current user, environment, version, and other useful information.
func (*App) OnShutdown ¶
OnShutdown registers a function to be called when the app is shutting down
func (*App) OnTemplateData ¶
func (a *App) OnTemplateData(fn OnTemplateDataFunc)
OnTemplateData registers a function that populates template data each time a template is rendered.
func (*App) RegisterModule ¶
RegisterModule adds a module to the app
func (*App) RunInBackground ¶
RunInBackground runs a function in the background via the server
func (*App) Session ¶
func (a *App) Session() *scs.SessionManager
Session returns the session manager instance for the app
func (*App) ShutdownServer ¶
ShutdownServer gracefully shuts down the server
func (*App) StartModules ¶
StartModules initializes and starts all modules without starting the server
func (*App) Stop ¶
Stop gracefully shuts down the app and all modules. This is only called when the server is shutting down.
func (*App) TM ¶
func (a *App) TM() *render.TemplateManager
TM returns the template manager instance for the app
type AppConfig ¶
type AppConfig struct { Config *conf.HopConfig Logger *slog.Logger TemplateSources render.Sources TemplateFuncs template.FuncMap TemplateExt string SessionStore scs.Store Stdout io.Writer Stderr io.Writer }
AppConfig is a configuration for the app
type ConfigurableModule ¶
ConfigurableModule represents a module that can be configured
type DispatcherModule ¶ added in v0.0.22
type DispatcherModule interface { Module RegisterEvents(events *dispatch.Dispatcher) }
DispatcherModule represents a module that can handle events
type HTTPModule ¶
HTTPModule represents a module that can add routes to the router
type OnTemplateDataFunc ¶
OnTemplateDataFunc is a function type that takes an HTTP request and a pointer to a map of data. It represents a callback function that can be used to populate data for templates.
type ShutdownModule ¶
ShutdownModule represents a module that has a shutdown process
type StartupModule ¶
StartupModule represents a module that has a startup process
Directories ¶
Path | Synopsis |
---|---|
Package conf provides a way to load configuration from JSON files and environment variables, along with a structure to hold the configuration settings for an application and the ability to set up command-line flags for configuration options.
|
Package conf provides a way to load configuration from JSON files and environment variables, along with a structure to hold the configuration settings for an application and the ability to set up command-line flags for configuration options. |
Package cookies provides helpers for reading and writing cookies with various security features.
|
Package cookies provides helpers for reading and writing cookies with various security features. |
Package db provides database-related helpers and utilities.
|
Package db provides database-related helpers and utilities. |
postgres
Module
|
|
sqlite_cgo
Module
|
|
sqlite_modernc
Module
|
|
Package dispatch provides a lightweight, type-safe event bus implementation for building event-driven applications in Go.
|
Package dispatch provides a lightweight, type-safe event bus implementation for building event-driven applications in Go. |
internal
|
|
Package logger provides some utility methods based around the standard library's slog.Logger package.
|
Package logger provides some utility methods based around the standard library's slog.Logger package. |
Package mail provides a simple mailer that sends emails using the SMTP protocol.
|
Package mail provides a simple mailer that sends emails using the SMTP protocol. |
Package pulse provides standardized metrics collection for hop applications
|
Package pulse provides standardized metrics collection for hop applications |
middleware
Package middleware provides HTTP middleware components for the route package.
|
Package middleware provides HTTP middleware components for the route package. |
secure
|
|
password
Package password provides functions for hashing and verifying passwords.
|
Package password provides functions for hashing and verifying passwords. |
Package serve provides a way to create and manage an HTTP server, including routing, middleware, and graceful shutdown.
|
Package serve provides a way to create and manage an HTTP server, including routing, middleware, and graceful shutdown. |
sess
|
|
Package wrap provides a way to create middleware chains for HTTP handlers in Go.
|
Package wrap provides a way to create middleware chains for HTTP handlers in Go. |