machine

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package machine proxies requests to the Meticulous machine HTTP API.

Rather than re-modelling every endpoint as typed Go, caffeine forwards /api/machine/* to the machine and lets the frontend speak the upstream JSON directly. This keeps the backend thin for read-only operations and gives us a single place to add auth, caching, and rate-limiting later.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Proxy

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

Proxy forwards requests to the configured machine base URL.

func New

func New(baseURL string) (*Proxy, error)

New builds a Proxy. baseURL must include scheme (e.g. http://meticulous.local).

func (*Proxy) Handler

func (p *Proxy) Handler() http.Handler

Handler returns the reverse proxy handler (mount at /api/machine).

func (*Proxy) Status

func (p *Proxy) Status(ctx context.Context) StatusResult

Status probes the machine's root URL and reports reachability, with retry + sticky-online behavior tuned for the machine's flaky wifi.

  • We probe `/` (the SPA root, always 200, tiny payload). Some firmwares 404 on `/api/v1/settings`.
  • Up to 3 attempts per call, ~3s each, with 250ms backoff. A burst of TX retries on the wifi chip blows one attempt without flipping the pill.
  • Any HTTP response — including 5xx — counts as reachable.
  • If the current probe fails but we've heard from the machine in the last ~90 seconds, we report Reachable=true + Degraded=true so the UI doesn't oscillate between online/offline on transient drops.

type StatusResult

type StatusResult struct {
	Reachable  bool   `json:"reachable"`
	MachineURL string `json:"machine_url"`
	Error      string `json:"error,omitempty"`
	StatusCode int    `json:"status_code,omitempty"`

	// Degraded is true when the *current* probe failed but the machine
	// answered within stickyOnlineWindow. The pill stays green-ish but
	// the UI can show a "flaky" hint. Degraded implies Reachable=true.
	Degraded bool `json:"degraded,omitempty"`

	// LastSeenUnix is the wall-clock seconds at which the machine last
	// answered any probe. Zero if it never has.
	LastSeenUnix int64 `json:"last_seen_unix,omitempty"`

	// Attempts is how many probe attempts the call made before returning.
	// Useful for surfacing "machine took 2 retries" in the UI/logs.
	Attempts int `json:"attempts,omitempty"`
}

Status probes the machine and reports reachability.

Jump to

Keyboard shortcuts

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