server

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package server provides common bootstrapping for all Nivo services.

Index

Constants

View Source
const (
	ReadTimeout     = 15 * time.Second
	WriteTimeout    = 15 * time.Second
	IdleTimeout     = 60 * time.Second
	ShutdownTimeout = 30 * time.Second
)

HTTP server timeouts

Variables

This section is empty.

Functions

func GetEnv

func GetEnv(key, defaultValue string) string

GetEnv returns the environment variable value or a default value.

func RequireEnv

func RequireEnv(key string) string

RequireEnv returns the environment variable value or panics if not set. Use this for required configuration like JWT_SECRET.

func Run

func Run(cfg ServiceConfig)

Run bootstraps and runs the service with common initialization.

Types

type BootstrapContext

type BootstrapContext struct {
	Logger *logger.Logger
	Config *config.Config
	DB     *database.DB
}

BootstrapContext contains initialized resources for service setup.

type ServiceConfig

type ServiceConfig struct {
	// Name is the service name (used for logging and identification).
	Name string

	// SetupHandler is called after DB connection to initialize
	// repositories, services, and handlers. Returns the HTTP handler.
	SetupHandler func(ctx *BootstrapContext) (http.Handler, error)

	// Cleanup is called during graceful shutdown (optional).
	// Use this for closing additional resources like Redis connections.
	Cleanup func() error
}

ServiceConfig defines how to bootstrap and run a service.

Jump to

Keyboard shortcuts

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