http

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ActorFrom

func ActorFrom(ctx context.Context) model.Actor

ActorFrom returns the authenticated actor from the request context. Panics if called without auth middleware (programming error, not a runtime condition).

func HashAPIKey

func HashAPIKey(key string) string

HashAPIKey is the exported version for use by bootstrap/tests.

Types

type Route

type Route struct {
	Name    string
	Path    string
	Summary string
	MinRole model.Role
	Input   any // nil for resources
	Output  any
	Params  []model.QueryParam // derived from Filter/Sort structs for resources
	Method  string             // "GET", "POST", etc.
	Status  int                // 200, 201, 204
	Handler handler
}

Route is the HTTP-layer representation of a domain resource or operation.

func (Route) PathParams

func (r Route) PathParams() []model.PathParam

PathParams returns the path parameters inferred from the Path pattern.

type Server

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

Server is the HTTP API server for TaskFlow.

func NewServer

func NewServer(svc taskflow.TaskFlow, cfg ...ServerConfig) *Server

NewServer creates a new HTTP server backed by the given TaskFlow service.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler returns the http.Handler for use with httptest or a real server.

func (*Server) ListenAndServe

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

ListenAndServe starts the server on the given address with configured timeouts.

type ServerConfig

type ServerConfig struct {
	// IdempotencyCacheBytes is the maximum memory budget for the idempotency
	// key cache in bytes. Defaults to 50 MB if zero.
	IdempotencyCacheBytes int

	// EventBus enables SSE event streaming. If nil, the SSE endpoint returns 503.
	EventBus *eventbus.EventBus

	// MaxRequestBodyBytes limits the size of request bodies.
	// Defaults to 1 MB if zero.
	MaxRequestBodyBytes int64

	// ReadTimeout is the maximum duration for reading the entire request.
	// Defaults to 30 seconds if zero.
	ReadTimeout time.Duration

	// WriteTimeout is the maximum duration for writing the response.
	// Defaults to 60 seconds if zero (longer to support SSE).
	WriteTimeout time.Duration

	// IdleTimeout is the maximum duration an idle keep-alive connection
	// remains open. Defaults to 120 seconds if zero.
	IdleTimeout time.Duration

	// RateLimitPerSecond is the maximum requests per second per API key.
	// Defaults to 50 if zero. Set to -1 to disable.
	RateLimitPerSecond int

	// DevMode disables all rate limiting (per-key and global IP-based).
	// Opt-in only via TASKFLOW_DEV_MODE=true.
	DevMode bool
}

ServerConfig holds configuration for the HTTP server.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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