repos
/ orchard main

orchard

mirror

Every site I host, in one repo, along with the Cloudflare Tunnel and Caddy that front them. It's all Go, Vite, and SQLite, and it runs on a desktop at home with nothing listening on an inbound port.

blogbuncaddycloudflare-tunneldockergogolanghomelabhtml-templatemonorepoself-hostedseosqlitestatic-sitetypstuptime-monitoringviteweb-analytics

1.2 KB · 39 lines · Go Raw History
 1// The read only JSON view of every property, for chat.bythewood.me's tools.
 2//
 3// It reuses buildStatusPayload rather than assembling its own shape, so what a
 4// tool reads and what /properties/{id}/status reports cannot drift apart. The
 5// only thing added is the identity of the property, since the per property
 6// endpoint already knows which one it is and a list does not.
 7package main
 8
 9import (
10	"net/http"
11)
12
13type apiProperty struct {
14	ID        string        `json:"id"`
15	URL       string        `json:"url"`
16	Public    bool          `json:"public"`
17	Status    statusPayload `json:"status"`
18	Protected bool          `json:"protected"`
19}
20
21func (s *site) apiProperties(w http.ResponseWriter, r *http.Request) {
22	props, err := listProperties(r.Context(), s.db, "")
23	if err != nil {
24		writeJSON(w, http.StatusServiceUnavailable, map[string]any{"error": "unavailable"})
25		return
26	}
27	out := make([]apiProperty, 0, len(props))
28	for _, p := range props {
29		out = append(out, apiProperty{
30			ID:        p.ID.String(),
31			URL:       p.URL,
32			Public:    p.IsPublic,
33			Protected: p.IsProtected,
34			Status:    buildStatusPayload(p),
35		})
36	}
37	writeJSON(w, http.StatusOK, map[string]any{"properties": out})
38}