server

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 44 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package server exposes the supervisor over HTTP: the JSON API used by the CLI and dashboard, WebSocket streams, the embedded dashboard itself, and a reverse proxy that serves every server at http://<name>.localhost.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnContext

func ConnContext(ctx context.Context, _ net.Conn) context.Context

ConnContext gives each connection of the daemon's http.Server a place for its owner check (http.Server.ConnContext), so a keep-alive connection is looked up once rather than on every request.

func DashboardHostPath

func DashboardHostPath(stateDir string) string

DashboardHostPath is where the daemon keeps its dashboard's host name.

func IsDashboardHost

func IsDashboardHost(host string) bool

IsDashboardHost reports whether host has the form <label>.localhost of a dashboard host.

func TokenPath

func TokenPath(stateDir string) string

TokenPath is where the daemon keeps its token.

Types

type ConfigInfo

type ConfigInfo struct {
	Path        string   `json:"path"`
	PathDisplay string   `json:"pathDisplay"`
	Root        string   `json:"root"`
	Error       string   `json:"error,omitempty"`
	Warnings    []string `json:"warnings,omitempty"`
	StateDir    string   `json:"stateDir"`
	// Revision changes whenever the file's text changes.
	Revision string `json:"revision"`
	// Notify mirrors the notify setting for clients that notify themselves.
	Notify bool `json:"notify"`
}

ConfigInfo describes the loaded configuration file.

type ContainerDetails

type ContainerDetails struct {
	Name          string            `json:"name"`
	ID            string            `json:"id"`
	Image         string            `json:"image"`
	Command       string            `json:"command"`
	Created       time.Time         `json:"created"`
	RestartPolicy string            `json:"restartPolicy,omitempty"`
	Health        *HealthDetails    `json:"health,omitempty"`
	Error         string            `json:"error,omitempty"`
	Env           []EnvVar          `json:"env"`
	Mounts        []MountView       `json:"mounts"`
	Networks      []NetworkView     `json:"networks"`
	ConfigFiles   []string          `json:"configFiles,omitempty"`
	Labels        map[string]string `json:"labels,omitempty"`
}

ContainerDetails is what the dashboard shows about one container.

type ContainerRef

type ContainerRef struct {
	Name    string `json:"name"`
	Service string `json:"service,omitempty"`
	Server  string `json:"server,omitempty"`
}

ContainerRef names a container and the server it belongs to.

type Credentials

type Credentials struct {
	Token string
	Host  string // <label>.localhost
}

Credentials are the daemon's API token and its dashboard's host name.

func LoadCredentials

func LoadCredentials(stateDir, keepHost string) (Credentials, error)

LoadCredentials returns the token, creating it with private permissions, and a dashboard host: keepHost when it is one (an upgrade carries it over), else a new one, written for local clients. A state directory without a dashboard host predates host-bound sessions, when browsers kept the token itself as a cookie for 127.0.0.1; the token is replaced then, so such cookies stop working.

type DiscoverResult

type DiscoverResult struct {
	discover.Suggestion
	DirDisplay string `json:"dirDisplay"`
	DirConfig  string `json:"dirConfig"` // how dir would be written to the config
}

DiscoverResult is a suggestion with a free port reserved for it.

type EnvVar

type EnvVar struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

EnvVar is one environment variable; the dashboard masks secret-looking ones.

type Health

type Health struct {
	App       string    `json:"app"`
	Name      string    `json:"name"`
	Version   string    `json:"version"`
	PID       int       `json:"pid"`
	Port      int       `json:"port"`
	StartedAt time.Time `json:"startedAt"`
	// SampleIntervalMs is the spacing of cpuHistory/memHistory samples.
	SampleIntervalMs int `json:"sampleIntervalMs"`
	// IdleSampleIntervalMs is the spacing of usage samples while no client
	// shows usage. Its presence tells events clients they may send
	// {"usage": bool} to say whether they show usage now.
	IdleSampleIntervalMs int `json:"idleSampleIntervalMs"`
}

Health identifies the daemon to clients probing the port.

type HealthDetails

type HealthDetails struct {
	Status        string `json:"status"`
	FailingStreak int    `json:"failingStreak"`
	Output        string `json:"output,omitempty"`
	ExitCode      int    `json:"exitCode"`
}

HealthDetails is the latest health check result.

type Hello

type Hello struct {
	App     string         `json:"app"`
	Version string         `json:"version"`
	Paired  bool           `json:"paired"`
	Servers *remote.Counts `json:"servers,omitempty"` // only when paired
}

Hello is what a device learns before and after pairing.

type ListenerView

type ListenerView struct {
	ports.Listener
	CwdDisplay string `json:"cwdDisplay,omitempty"`
	Server     string `json:"server,omitempty"`    // configured server owning the port
	Managed    bool   `json:"managed"`             // process started by Portside
	Via        string `json:"via,omitempty"`       // "containers" when a runtime publishes a managed compose port
	Protected  string `json:"protected,omitempty"` // why it may not be killed
	// Container is the container whose published port this is.
	Container *ContainerRef `json:"container,omitempty"`
}

ListenerView is a listening process annotated with what Portside knows.

type MountView

type MountView struct {
	Type        string `json:"type"`
	Name        string `json:"name,omitempty"`
	Source      string `json:"source"`
	Destination string `json:"destination"`
	ReadOnly    bool   `json:"readOnly,omitempty"`
}

MountView is a volume or bind mount.

type NetworkView

type NetworkView struct {
	Name    string   `json:"name"`
	IP      string   `json:"ip,omitempty"`
	Aliases []string `json:"aliases,omitempty"`
}

NetworkView is one network the container is attached to.

type Options

type Options struct {
	ConfigError string
	Supervisor  *supervisor.Supervisor
	Docker      *docker.Monitor
	ConfigPath  string
	StateDir    string
	Port        int
	// PortAuto is true when the config set no port at start, so the daemon
	// chose Port itself (the default or a fallback port).
	PortAuto bool
	UI       fs.FS // dashboard assets; nil serves a placeholder
	// Token authenticates API clients; empty disables authentication.
	Token string
	// DashboardHost is the dashboard's own host name, <label>.localhost:
	// the only host whose requests may authenticate with the session cookie.
	DashboardHost string
	// Shutdown is called when a client asks the daemon to exit; restart is
	// true when the client starts a daemon again right after.
	Shutdown func(restart bool)
	// Upgrade re-executes the daemon from the binary at exe (its own when
	// empty), keeping servers running. It returns only when that did not
	// happen.
	Upgrade func(exe string) error
	// Remote connects to the daemon on another of the owner's devices.
	Remote *remote.Manager
	// Share lets the owner's other devices connect to this daemon.
	Share *share.Manager
}

Options configure a Server.

type RemoteOverview

type RemoteOverview struct {
	Share      share.Status `json:"share"`
	Connection *remote.Info `json:"connection"`
}

RemoteOverview is the answer of GET /api/remote.

type Server

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

Server is the daemon's HTTP surface.

func New

func New(opt Options) *Server

New builds the HTTP server.

func (*Server) Handler

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

Handler returns the root handler: it routes by Host between the proxy and the dashboard, and rejects unknown hosts to defeat DNS rebinding. The dashboard itself is served only on its own host; loopback addresses serve the API to signed clients and a page on how to open the dashboard.

func (*Server) PeerHandler

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

PeerHandler serves requests from the owner's other devices, after package share has verified them. It exposes the API and port tunnels, nothing else.

func (*Server) WatchConfig

func (s *Server) WatchConfig(ctx context.Context)

WatchConfig reloads the configuration when the file changes on disk.

func (*Server) WatchContainerIssues

func (s *Server) WatchContainerIssues(ctx context.Context)

WatchContainerIssues notifies once per unhealthy or failed transition for attached containers. A reconnect retains the previous observations.

type State

type State struct {
	Warnings []string          `json:"warnings,omitempty"`
	Daemon   Health            `json:"daemon"`
	Config   ConfigInfo        `json:"config"`
	Servers  []supervisor.View `json:"servers"`
	Groups   []string          `json:"groups"`
	Docker   docker.State      `json:"docker"`
	// Remote is the connection to another device, null when there is none.
	Remote *remote.Info `json:"remote"`
	// Paired lists the devices paired with this computer and whether each is
	// connected; never sent to those devices.
	Paired []share.DeviceStatus `json:"paired,omitempty"`
}

State is everything the dashboard renders.

Jump to

Keyboard shortcuts

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