pgdesign v0.26.0 /internal/serve
On this page

Package serve provides an HTTP API server and web UI for pgdesign schema inspection, validation, database statistics, and interactive exploration.

#internal/serve

#internal/serve

Package serve provides an HTTP API server and web UI for pgdesign schema inspection, validation, database statistics, and interactive exploration.

#PoolConfig

Go go
type PoolConfig struct

PoolConfig holds connection pool tuning parameters. Zero values mean pgxpool uses its built-in defaults.

#Server

Go go
type Server struct

Server is the HTTP API server for pgdesign. It runs in one of two explicit modes, chosen at construction (never a silent runtime fallback):

- database mode: pool is non-nil, project is nil. /schema introspects the live database (registry-absent class); the stats/migrations/extensions/ diff/audit endpoints read the database. - project mode: project is non-nil, pool is nil. /schema serves the compiled project model (registry-present class) with no database; database-only endpoints degrade with an explicit 503, never a nil-pool panic.

#New

Go go
func New(connStr string, schemas []string, migrationsDir string, poolCfg PoolConfig) (*Server, error)

New creates a new database-mode Server with a pgxpool connection and sets up routes. Pool parameters in poolCfg override pgxpool defaults when non-zero.

#NewFromPool

Go go
func NewFromPool(pool *pgxpool.Pool, schemas []string, migrationsDir string) *Server

NewFromPool creates a database-mode Server from an existing pgxpool.Pool (useful for tests).

#NewProject

Go go
func NewProject(schema *model.Schema, registry *semtype.Registry, diags []diagnostic.Diagnostic, schemas []string, migrationsDir string) *Server

NewProject creates a DB-free project-mode Server that serves a pre-compiled model. schema is the resolved model, registry is the semtype registry that produced it (enables state-machine D2 diagrams), and diags are the build diagnostics wrapped into the /schema envelope. There is no database: the stats/migrations/extensions/diff/audit endpoints return an explicit 503.

#badParamError.Error

Go go
func (e *badParamError) Error() string

#Server.SetRequestTimeout

Go go
func (s *Server) SetRequestTimeout(d time.Duration) { s.requestTimeout = d }

SetRequestTimeout sets the per-request deadline enforced by the server. A non-positive duration disables enforcement. It must be called before serving.

#Server.ListenAndServe

Go go
func (s *Server) ListenAndServe(addr string) error

ListenAndServe starts the HTTP server on the given address.

#Server.ServeHTTP

Go go
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler so the server can be used with httptest.

#Server.Close

Go go
func (s *Server) Close()

Close shuts down the connection pool. It is a no-op in project mode.

Search