Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                

server

package
v0.0.202 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2026 License: AGPL-3.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, srv *Server, addr string) error

Run starts the HTTP server and blocks until the context is cancelled.

Types

type Option

type Option func(*Server)

Option configures the Server returned by New.

func WithBus

func WithBus(b *eventbus.Bus) Option

WithBus sets the event bus used by the server.

func WithConfig

func WithConfig(cfg *config.RuntimeConfig) Option

WithConfig supplies the runtime configuration.

func WithConfigFile

func WithConfigFile(path string) Option

WithConfigFile sets the config file path.

func WithDB

func WithDB(db *sql.DB) Option

WithDB sets the database pool.

func WithDBRegistry

func WithDBRegistry(r *dbdrivers.Registry) Option

WithDBRegistry sets the database driver registry.

func WithDLQRegistry

func WithDLQRegistry(r *dlq.Registry) Option

WithDLQRegistry sets the dead letter queue registry.

func WithEmailRegistry

func WithEmailRegistry(r *email.Registry) Option

WithEmailRegistry sets the email provider registry.

func WithFeedSignKey

func WithFeedSignKey(key string) Option

WithFeedSignKey sets the feed signing key.

func WithHandler

func WithHandler(h http.Handler) Option

WithHandler sets the HTTP handler used by the server.

func WithImageSignKey

func WithImageSignKey(key string) Option

WithImageSignKey sets the image signing key.

func WithLinkSignKey

func WithLinkSignKey(key string) Option

WithLinkSignKey sets the external link signing key.

func WithNavRegistry

func WithNavRegistry(n *nav.Registry) Option

WithNavRegistry sets the navigation registry.

func WithQuerier

func WithQuerier(q db.Querier) Option

WithQuerier sets a custom query implementation for the server.

func WithRouterRegistry

func WithRouterRegistry(r *router.Registry) Option

WithRouterRegistry sets the router registry.

func WithSessionManager

func WithSessionManager(sm common.SessionManager) Option

WithSessionManager sets the session manager used by the server.

func WithShareSignKey

func WithShareSignKey(key string) Option

WithShareSignKey sets the share signing key.

func WithStore

func WithStore(store *sessions.CookieStore) Option

WithStore sets the session store used by the server.

func WithTasksRegistry

func WithTasksRegistry(r *tasks.Registry) Option

WithTasksRegistry sets the tasks registry used by the server.

func WithWebsocket

func WithWebsocket(w *websocket.Module) Option

WithWebsocket sets the websocket module.

type Server

type Server struct {
	RouterReg       *router.Registry
	Nav             *nav.Registry
	Config          *config.RuntimeConfig
	ConfigFile      string
	Router          http.Handler
	NotFoundHandler http.Handler
	Store           *sessions.CookieStore
	DB              *sql.DB
	Queries         db.Querier
	Bus             *eventbus.Bus
	EmailReg        *email.Registry

	// Signing keys (simple strings, no complex objects)
	FeedSignKey  string
	ImageSignKey string
	LinkSignKey  string
	ShareSignKey string

	SessionManager common.SessionManager
	TasksReg       *tasks.Registry
	DBReg          *dbdrivers.Registry
	DLQReg         *dlq.Registry
	Websocket      *websocket.Module
	LanguageCache  *common.LanguageCache

	WorkerCancel context.CancelFunc
	// contains filtered or unexported fields
}

Server bundles the application's configuration, router and runtime dependencies.

func New

func New(opts ...Option) *Server

New returns a Server configured using the supplied options.

func (*Server) Addr

func (s *Server) Addr() string

Addr returns the address the server is listening on after Start is called.

func (*Server) Close

func (s *Server) Close()

Close releases resources associated with the server such as background workers, the event bus and the database connection.

func (*Server) CoreDataMiddleware

func (s *Server) CoreDataMiddleware() func(http.Handler) http.Handler

func (*Server) GetCoreData

func (s *Server) GetCoreData(w http.ResponseWriter, r *http.Request) (*common.CoreData, *http.Request)

CoreDataMiddleware constructs the middleware responsible for populating CoreData in the request context using the server's configured dependencies.

func (*Server) RunContext

func (s *Server) RunContext(ctx context.Context) error

RunContext starts the server using the configured HTTPListen address.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown gracefully stops the HTTP server.

func (*Server) Start

func (s *Server) Start(addr string) error

Start begins serving HTTP requests on the given address. If the port is specified as :0, the automatically chosen address can be retrieved via Addr().

Jump to

Keyboard shortcuts

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