server

package
v0.1.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	JobStatusQueued   = "queued"
	JobStatusRunning  = "running"
	JobStatusDone     = "done"
	JobStatusFailed   = "failed"
	JobStatusCanceled = "canceled"
)

Variables

View Source
var ErrJobNotFound = errors.New("job not found")
View Source
var Version = "dev"

Version is the API version value. It can be overridden with -ldflags.

Functions

func ConcurrencyLimitMiddleware

func ConcurrencyLimitMiddleware(maxConcurrent int) func(http.Handler) http.Handler

ConcurrencyLimitMiddleware bounds concurrent conversion work with a semaphore.

func SizeLimitMiddleware

func SizeLimitMiddleware(maxBytes int64) func(http.Handler) http.Handler

SizeLimitMiddleware rejects requests whose advertised body size exceeds maxBytes. It also wraps accepted bodies with http.MaxBytesReader for downstream readers.

Types

type CleanupManager

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

CleanupManager removes stale temporary files from uploads/downloads storage.

func NewCleanupManager

func NewCleanupManager(tempDir string, ttl time.Duration, logger *slog.Logger) *CleanupManager

func (*CleanupManager) CleanupOnce

func (c *CleanupManager) CleanupOnce() error

func (*CleanupManager) Start

func (c *CleanupManager) Start()

Start launches cleanup in the background. Missing tempDir never blocks startup.

func (*CleanupManager) Stop

func (c *CleanupManager) Stop()

Stop signals the background cleanup goroutine to stop.

type Job

type Job struct {
	ID          string     `json:"id"`
	Status      string     `json:"status"`
	UploadID    string     `json:"upload_id"`
	From        string     `json:"from"`
	To          string     `json:"to"`
	CreatedAt   time.Time  `json:"created_at"`
	CompletedAt *time.Time `json:"completed_at,omitempty"`
	ResultPath  string     `json:"-"`
	Error       string     `json:"error,omitempty"`
	Warnings    []string   `json:"warnings,omitempty"`
}

type JobCompleteEvent

type JobCompleteEvent struct {
	Event       string   `json:"event"`
	JobID       string   `json:"jobID"`
	DownloadURL string   `json:"downloadURL"`
	Warnings    []string `json:"warnings,omitempty"`
}

type JobErrorEvent

type JobErrorEvent struct {
	Event    string   `json:"event"`
	JobID    string   `json:"jobID"`
	Error    string   `json:"error"`
	Warnings []string `json:"warnings,omitempty"`
}

type JobManager

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

func NewJobManager

func NewJobManager() *JobManager

func (*JobManager) CreateJob

func (m *JobManager) CreateJob(uploadID, from, to string) (*Job, error)

func (*JobManager) DeleteJob

func (m *JobManager) DeleteJob(id string) bool

func (*JobManager) GetJob

func (m *JobManager) GetJob(id string) (*Job, error)

func (*JobManager) ListJobs

func (m *JobManager) ListJobs() []*Job

func (*JobManager) PruneJobs

func (m *JobManager) PruneJobs(before time.Time) int

func (*JobManager) UpdateStatus

func (m *JobManager) UpdateStatus(id, status, resultPath, errMsg string)

func (*JobManager) UpdateStatusWithWarnings added in v0.1.2

func (m *JobManager) UpdateStatusWithWarnings(id, status, resultPath, errMsg string, warnings []string)

type JobProgressEvent

type JobProgressEvent struct {
	Event    string   `json:"event"`
	JobID    string   `json:"jobID"`
	Status   string   `json:"status"`
	Message  string   `json:"message"`
	Warnings []string `json:"warnings,omitempty"`
}

type JobStore

type JobStore interface {
	GetJob(id string) (*Job, error)
}

JobStore abstracts job lookup so WU-2 can provide the concrete JobManager.

type SSEWriter

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

SSEWriter writes Server-Sent Events using the standard event/data format.

func NewSSEWriter

func NewSSEWriter(w http.ResponseWriter) (*SSEWriter, error)

NewSSEWriter configures the response for Server-Sent Events.

func (*SSEWriter) WriteEvent

func (s *SSEWriter) WriteEvent(event string, data any) error

WriteEvent writes and flushes one SSE event.

type Server

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

Server wraps the conversion engine and HTTP server.

func NewServer

func NewServer(engine *core.Engine, addr string, opts ...ServerOption) *Server

NewServer constructs a server with all API routes registered.

func (*Server) Handler

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

Handler returns the HTTP handler for tests and embedding.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

ListenAndServe starts the HTTP server.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown gracefully drains in-flight requests and stops the HTTP server.

type ServerMode

type ServerMode int

ServerMode controls whether the server exposes the web UI or runs as a public API only. The zero value defaults to ServerModeLocalUI.

const (
	// ServerModeLocalUI serves both the web UI and the API (default).
	ServerModeLocalUI ServerMode = iota
	// ServerModePublicAPI serves only the API; UI routes return 404.
	ServerModePublicAPI
)

type ServerOption

type ServerOption func(*Server)

ServerOption configures Server construction.

func WithCORSOrigin

func WithCORSOrigin(origin string) ServerOption

WithCORSOrigin sets the Access-Control-Allow-Origin value.

func WithLogger

func WithLogger(logger *slog.Logger) ServerOption

WithLogger sets the logger used by middleware.

func WithMaxRunningJobs

func WithMaxRunningJobs(n int) ServerOption

WithMaxRunningJobs sets the maximum number of concurrently running conversion jobs. Jobs beyond the limit remain queued until a slot opens.

func WithMaxUploadSize

func WithMaxUploadSize(size int64) ServerOption

WithMaxUploadSize sets the maximum request body size reserved for future endpoints.

func WithRequestTimeout

func WithRequestTimeout(timeout time.Duration) ServerOption

WithRequestTimeout sets the per-request timeout.

func WithServerMode

func WithServerMode(mode ServerMode) ServerOption

WithServerMode sets the server mode which controls UI availability. ServerModeLocalUI enables the web UI; ServerModePublicAPI disables it.

func WithUI

func WithUI(enabled bool) ServerOption

WithUI enables or disables the web UI.

func WithVersion

func WithVersion(version string) ServerOption

WithVersion sets the version returned by /api/v1/version.

Directories

Path Synopsis
templ: version: v0.3.1020
templ: version: v0.3.1020

Jump to

Keyboard shortcuts

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