Documentation
¶
Overview ¶
Package apiserver is the embedded REST control plane of the go-apps family: a small, self-contained HTTP server guarded by an API key and an IP allowlist (CIDRs). It serves the app descriptor (/v1/ax), health, and the UI-bridge endpoints (/v1/ui/*) that let an automated client operate the real frontend; each app registers its own domain endpoints with HandleExtra. Optional HTTPS uses a self-signed certificate whose public-key pin stays stable across restarts (see tls.go).
Index ¶
- func BindHost(allowlist []string) string
- func DecodeJSON(w http.ResponseWriter, r *http.Request, req any) bool
- func NormalizeCIDR(s string) (string, error)
- func OutboundIP() string
- func WriteErr(w http.ResponseWriter, status int, code, msg string)
- func WriteJSON(w http.ResponseWriter, code int, v any)
- type Config
- type InfoFunc
- type Server
- type UIController
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BindHost ¶
BindHost returns "127.0.0.1" when every allowlisted CIDR is loopback (so the server stays local and no firewall prompt appears), or "0.0.0.0" when a non-loopback IP is allowed and LAN access is actually intended.
func DecodeJSON ¶
DecodeJSON is the request-side helper for POST endpoints (built-in and HandleExtra alike): it enforces the method, caps the body at 1 MiB and decodes the JSON into req, answering the structured 405/400 itself. Returns false when the response has already been written.
func NormalizeCIDR ¶
NormalizeCIDR validates user input and returns the canonical CIDR. A bare IP gets a host mask (/32 or /128) so the allowlist always carries a mask.
func OutboundIP ¶
func OutboundIP() string
OutboundIP returns the machine's primary LAN IP (no packets are sent).
Types ¶
type InfoFunc ¶
type InfoFunc func() any
InfoFunc returns the app descriptor / accessibility tree served at /v1/ax.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func New ¶
func New(info InfoFunc, ui UIController) *Server
func (*Server) CertPEM ¶
CertPEM is the current self-signed certificate, for `curl --cacert` export. Nil when serving plain HTTP.
func (*Server) Fingerprint ¶
Fingerprint is the public-key pin a client fixes (base64 SHA-256 SPKI). Empty when serving plain HTTP.
func (*Server) HandleExtra ¶
func (s *Server) HandleExtra(path string, h http.HandlerFunc)
HandleExtra registers an app-specific endpoint (e.g. "/v1/stats", "/v1/update") served behind the same key + allowlist middleware as the built-in routes. Register before Start; a running server picks it up on its next (re)start. Use DecodeJSON / WriteJSON / WriteErr inside the handler to honour the family's structured contract.
type UIController ¶
type UIController interface {
State() (any, error)
Press(testid string) (any, error)
DblClick(testid string) (any, error)
Key(key string) (any, error)
Input(testid, value string) (any, error)
}
UIController drives the live frontend so a client can test the actual UI: read what is on screen, click controls by testid, press keys, type into inputs. Each call returns the resulting UI state. Implemented by the host app over its UI framework (in the family apps: Wails events → Vue).