api

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: May 29, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package api provides HTTP handlers, middleware, and routing for the user preferences service.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoggerMiddleware

func LoggerMiddleware(logger userprefs.Logger) func(next http.Handler) http.Handler

LoggerMiddleware returns a middleware that logs requests using the provided logger.

Types

type Config

type Config struct {
	ListenAddress string
	Manager       *userprefs.Manager
	Logger        userprefs.Logger
}

Config holds configuration for the API server. TODO: Expand with Address, TLS config, timeouts etc.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server holds the dependencies for the HTTP server.

func NewServer

func NewServer(cfg Config) (*Server, error)

NewServer creates and configures a new API server instance.

func (*Server) Start

func (s *Server) Start() error

Start runs the HTTP server. This method is blocking and will only return when the server is shut down or an unrecoverable error occurs (e.g., failure to bind to the address). If non-blocking behavior is desired, the caller should run this method in a separate goroutine. It logs the server startup and shutdown events. Returns http.ErrServerClosed if the server is gracefully shut down, nil otherwise for graceful shutdown scenarios handled by ListenAndServe itself, or an error if the server fails to start or stops unexpectedly.

func (*Server) Stop

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

Stop gracefully shuts down the HTTP server.

Jump to

Keyboard shortcuts

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