web

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultPort = 8787

DefaultPort is the eget web default listen port.

Variables

This section is empty.

Functions

func IsLoopbackHost

func IsLoopbackHost(host string) bool

IsLoopbackHost reports whether host only accepts local connections.

func TaskParamBool

func TaskParamBool(params map[string]any, key string) bool

TaskParamBool reads a boolean parameter that arrived as JSON.

func TaskParamInt

func TaskParamInt(params map[string]any, key string) int

TaskParamInt reads a numeric parameter that arrived as JSON (json numbers decode into float64).

func TaskParamString

func TaskParamString(params map[string]any, key string) string

TaskParamString reads a string parameter that arrived as JSON.

func TaskParamStrings

func TaskParamStrings(params map[string]any, key string) []string

TaskParamStrings reads a []string parameter that arrived as JSON.

Types

type CacheProvider

type CacheProvider interface {
	ResolveCacheDir() (string, error)
	List(cacheDir string, opts appcache.ListOptions) (appcache.ListResult, error)
	Status(cacheDir string) (appcache.StatusResult, error)
}

CacheProvider is the subset of appcache.Service the console needs.

type ConfigProvider

type ConfigProvider interface {
	ConfigInfo() (app.ConfigInfoResult, error)
	ConfigExport(out io.Writer, withGlobal bool) error
	ConfigGet(key string) (any, error)
	ConfigSet(key, value string) error
}

ConfigProvider is the subset of app.ConfigService the console needs.

type Deps

type Deps struct {
	List   ListProvider
	Show   ShowProvider
	Query  QueryProvider
	Search SearchProvider
	Config ConfigProvider
	Cache  CacheProvider
	Ext    ExtProvider

	// Machine handlers serve the cache mirror protocol on its original paths
	// (/manifest.json, /download/*, /files/*).
	Manifest http.HandlerFunc
	Download http.HandlerFunc
	File     http.HandlerFunc

	// AssetCandidates lists the assets matching a target without downloading,
	// so the install form can offer an explicit choice.
	AssetCandidates func(ctx context.Context, target string) ([]string, error)

	// ListWithManagers returns the list provider scoped to a manager selection,
	// which is how /api/outdated filters to eget-only or one external manager
	// without rebuilding the service.
	ListWithManagers func(app.ManagersSelection) ListProvider
}

Deps are the application services the console calls.

type Engine

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

Engine runs one task at a time — the store and external managers do not tolerate concurrent writers — and publishes every state change to SSE subscribers through a keyed hub.

func NewEngine

func NewEngine(storePath string, runners map[string]TaskRunner) *Engine

NewEngine restores persisted task history and starts the single worker.

func (*Engine) Cancel

func (e *Engine) Cancel(id string) error

Cancel stops a queued or running task.

func (*Engine) Close

func (e *Engine) Close()

Close cancels running tasks and stops the worker. Queued tasks are dropped.

func (*Engine) Counts

func (e *Engine) Counts() (running int, queued int)

Counts reports running and queued task counts for /api/overview.

func (*Engine) Get

func (e *Engine) Get(id string) (Task, bool)

Get returns a copy of one task.

func (*Engine) Hub

func (e *Engine) Hub() *sse.Hub

Hub exposes the SSE hub used by /api/tasks/{id}/events.

func (*Engine) List

func (e *Engine) List(limit int) []Task

List returns tasks newest first, capped at limit when limit > 0.

func (*Engine) Submit

func (e *Engine) Submit(kind string, params map[string]any) (string, error)

Submit queues a task of the given kind and returns its id.

type ExtProvider

type ExtProvider interface {
	Names() []string
	Manager(name string) (extpkg.Manager, bool)
	Path(manager extpkg.Manager) (string, bool)
	List(ctx context.Context, only ...string) ([]extpkg.Package, []extpkg.Failure, error)
	Outdated(ctx context.Context, only ...string) ([]extpkg.Package, []extpkg.Failure, error)
}

ExtProvider is the subset of extpkg.Service the console needs.

type ListProvider

type ListProvider interface {
	ListPackages() ([]app.ListItem, error)
	ListInstalledPackages() ([]app.ListItem, error)
	ListOutdatedPackages() ([]app.OutdatedItem, []app.OutdatedCheckFailure, int, error)
	FindPackage(name string) (*app.ListItem, error)
}

ListProvider is the subset of app.ListService the console needs.

type LogLine

type LogLine struct {
	Time    time.Time `json:"time"`
	Level   string    `json:"level"`
	Message string    `json:"message"`
}

type Options

type Options struct {
	Host           string
	Port           int
	Token          string
	ReadOnly       bool
	AllowMutations bool
	Version        string
	CacheRoot      string
	NoCacheIndex   bool
	// AllowHosts adds names to the Host header allow list.
	AllowHosts []string
	JSONLog    bool
	LogWriter  io.Writer
	// TaskStore is the tasks.json path (empty disables persistence).
	TaskStore string
	// TaskRunners maps a task kind to its implementation. Write endpoints are
	// unavailable when it is empty.
	TaskRunners map[string]TaskRunner
}

Options configures the eget web console.

func (Options) NoAuth

func (o Options) NoAuth() bool

NoAuth reports whether the console runs without token checks.

type QueryProvider

type QueryProvider interface {
	Query(opts app.QueryOptions) (app.QueryResult, error)
}

QueryProvider is the subset of app.QueryService the console needs.

type SearchProvider

type SearchProvider interface {
	Search(opts app.SearchOptions) (app.SearchResult, error)
}

SearchProvider is the subset of app.SearchService the console needs.

type Server

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

Server hosts the eget web console over HTTP.

func NewServer

func NewServer(deps Deps, opts Options) (*Server, error)

NewServer builds the router, middleware chain and cache mirror routes.

func (*Server) Handler

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

Handler exposes the router for tests and httptest servers.

func (*Server) MutationsEnabled

func (s *Server) MutationsEnabled() bool

MutationsEnabled reports whether write endpoints may run.

func (*Server) Router

func (s *Server) Router() *rux.Router

Router exposes the underlying router, for tests that register extra routes before the first request freezes the routing table.

func (*Server) Serve

func (s *Server) Serve(ctx context.Context, onReady func(addr string)) error

Serve listens on the configured address and blocks until a stop signal or a canceled ctx, then drains in-flight requests. onReady receives the address actually bound, which resolves a random port when Port is 0.

type ShowProvider

type ShowProvider interface {
	ShowPackage(target string) (app.ShowResult, error)
}

ShowProvider is the subset of app.ShowService the console needs.

type Task

type Task struct {
	ID         string         `json:"id"`
	Kind       string         `json:"kind"`
	Params     map[string]any `json:"params,omitempty"`
	Status     TaskStatus     `json:"status"`
	CreatedAt  time.Time      `json:"createdAt"`
	StartedAt  *time.Time     `json:"startedAt,omitempty"`
	FinishedAt *time.Time     `json:"finishedAt,omitempty"`
	Progress   TaskProgress   `json:"progress"`
	Logs       []LogLine      `json:"logs,omitempty"`
	Result     any            `json:"result,omitempty"`
	Error      string         `json:"error,omitempty"`
}

type TaskProgress

type TaskProgress struct {
	Percent float64 `json:"percent"`
	Phase   string  `json:"phase,omitempty"`
	Current int64   `json:"current,omitempty"`
	Total   int64   `json:"total,omitempty"`
}

type TaskReporter

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

TaskReporter is how a running task pushes log lines and progress.

func (*TaskReporter) Error

func (r *TaskReporter) Error(format string, args ...any)

func (*TaskReporter) Info

func (r *TaskReporter) Info(format string, args ...any)

func (*TaskReporter) Logf

func (r *TaskReporter) Logf(level, format string, args ...any)

func (*TaskReporter) Progress

func (r *TaskReporter) Progress(percent float64, phase string)

func (*TaskReporter) ProgressBytes

func (r *TaskReporter) ProgressBytes(current, total int64, phase string)

type TaskRunner

type TaskRunner func(ctx context.Context, params map[string]any, report *TaskReporter) (any, error)

TaskRunner performs one queued task. It must honor ctx cancellation and return a JSON-serializable result.

type TaskStatus

type TaskStatus string

TaskStatus is the lifecycle state of a console task.

const (
	StatusQueued    TaskStatus = "queued"
	StatusRunning   TaskStatus = "running"
	StatusSucceeded TaskStatus = "succeeded"
	StatusFailed    TaskStatus = "failed"
	StatusCanceled  TaskStatus = "canceled"
	// StatusInterrupted marks a task that was still running when the process
	// exited; the engine cannot resume it after a restart.
	StatusInterrupted TaskStatus = "interrupted"
)

Jump to

Keyboard shortcuts

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