server

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package server wires foundry's HTTP layer together and exposes the App that feature modules (crm, analytics, …) register themselves onto. server does NOT import the modules — main does the wiring — so there is no import cycle.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientIP

func ClientIP(r *http.Request) string

ClientIP best-effort extracts the caller's IP, honoring X-Forwarded-For when behind a proxy. Used by the analytics module to build the daily-salted, non-reversible visitor hash (the IP itself is never stored).

Types

type App

type App struct {
	Cfg   *config.Config
	Store *store.Store
	Mux   *http.ServeMux
	// contains filtered or unexported fields
}

App is the shared context handed to every module's Register function.

func New

func New(cfg *config.Config, st *store.Store) (*App, error)

New builds the App, loads templates, and mounts the base routes (static assets, auth, health, and the home dashboard). Modules are registered by the caller afterwards.

func (*App) Handler

func (a *App) Handler() http.Handler

Handler returns the root http.Handler with light middleware.

func (*App) Partial

func (a *App) Partial(w http.ResponseWriter, name string, data any)

Partial writes a single htmx fragment by its {{define}} name.

func (*App) Render

func (a *App) Render(w http.ResponseWriter, r *http.Request, page string, v View)

Render writes a full page (base layout + the named page template).

func (*App) RequireAuth

func (a *App) RequireAuth(next http.HandlerFunc) http.HandlerFunc

RequireAuth wraps a handler so only an authenticated admin can reach it.

type View

type View struct {
	Title  string
	Active string // nav key: "crm", "analytics", "home"
	Flash  string
	Data   any
}

View is the envelope every full page receives. Modules put their payload in Data; the base layout reads Title/Active/Flash for the chrome.

Jump to

Keyboard shortcuts

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