httpapi

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

README

HTTP Interface Module

Thin HTTP adapter for exposing the offline DeltaScope audit engine as a JSON service.

Files

File Responsibility
handler.go Binds Gin HTTP requests to the public audit API, auth checks, and JSON responses
handler_test.go Verifies HTTP request binding, error mapping, and JSON response shape
server.go Assembles the HTTP handler and long-running server wiring

Exports

  • NewHandler(configPath, version, opts ...HandlerOption) (http.Handler, error)
  • WithAuthConfig(AuthConfig) HandlerOption
  • WithMiddlewareConfig(MiddlewareConfig) HandlerOption
  • WithAuditFunc(func(context.Context, deltascope.Request) (deltascope.Result, error)) HandlerOption
  • NewServer(addr, configPath, version, opts ...HandlerOption)

Notes

  • The HTTP layer is adapter-only: it reuses the same offline audit engine as the CLI and library.
  • Routing uses Gin while keeping the public JSON API contract unchanged.
  • API-key auth is optional and configured through adapter options.
  • Rate limiting is optional and supports api-key or ip bucketing.
  • /metrics is exposed in Prometheus format by default and can be disabled via middleware config.
  • Default middleware chain is request-id -> recovery -> timeout -> metrics -> auth -> rate-limit -> access log.
  • Config hot-reload is achieved by re-reading the configured policy path on each audit request, so file updates take effect without restarting the server.
  • The service intentionally stays JSON-only in this milestone.

Dependencies

  • Upstream: cmd/deltascope-server
  • Downstream: pkg/deltascope, internal/application/policy

Update Rule

  • If members/interfaces/dependencies change, update this file in same change.

Documentation

Overview

Package httpapi exposes the HTTP adapter for DeltaScope. input: HTTP requests carrying SQL audit payloads plus service-level config/version wiring output: JSON audit, health, version, and structured error responses pos: interface adapter between net/http and the public DeltaScope audit API note: if this file changes, update this header and module README.md.

Package httpapi exposes the HTTP adapter for DeltaScope. input: listen addresses plus service-level config/version wiring output: ready-to-run HTTP server instances for the JSON audit service pos: long-running net/http server assembly for the HTTP interface milestone note: if this file changes, update this header and module README.md.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHandler

func NewHandler(configPath, version string, opts ...HandlerOption) (http.Handler, error)

NewHandler returns the JSON HTTP adapter for DeltaScope.

func NewServer

func NewServer(addr, configPath, version string, opts ...HandlerOption) (*http.Server, error)

NewServer builds the DeltaScope HTTP service.

Types

type AuthConfig added in v0.10.0

type AuthConfig struct {
	Enabled    bool
	Keys       []string
	AllowPaths []string
}

AuthConfig controls API-key authentication on the HTTP adapter.

type HandlerOption added in v0.10.0

type HandlerOption func(*handlerOptions)

HandlerOption configures NewHandler behavior.

func WithAuditFunc added in v0.10.0

WithAuditFunc overrides the audit execution function (primarily for tests).

func WithAuthConfig added in v0.10.0

func WithAuthConfig(cfg AuthConfig) HandlerOption

WithAuthConfig enables API-key authentication on selected routes.

func WithMiddlewareConfig added in v0.10.0

func WithMiddlewareConfig(cfg MiddlewareConfig) HandlerOption

WithMiddlewareConfig overrides default middleware settings.

type MiddlewareConfig added in v0.10.0

type MiddlewareConfig struct {
	RequestTimeout time.Duration
	Logger         *log.Logger
	RateLimit      RateLimitConfig
	MetricsEnabled *bool
	TrustedProxies []string
}

MiddlewareConfig controls default middleware behavior.

type RateLimitConfig added in v0.10.0

type RateLimitConfig struct {
	Enabled    bool
	RPS        float64
	Burst      int
	KeyBy      string
	AllowPaths []string
}

RateLimitConfig controls per-key request throttling.

Jump to

Keyboard shortcuts

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