oficina / base Public

Clone
git clone https://amadan.net/oficina/base

Plain git — no account needed to clone.

Download

Download this file

1package web
2
3import (
4 "encoding/json"
5 "net/http"
6)
7
8// teamProbe answers GET /api/team, the readiness probe Alta reads before
9// it activates a team Base in Home's directory (oficina/alta
10// design/team-bundle, spec §1.2). Base has no Home roster mode: its owner
11// is seeded from BASE_OWNER, so it answers in the seeded mode. It names
12// the Home consumer it was configured as, and whether an owner exists yet.
13// It carries no address, name or count, and needs no session.
14//
15// A Base without Oficina ID has no consumer and is never ready: 404.
16func (a *app) teamProbe(w http.ResponseWriter, r *http.Request) {
17 if a.cfg.Home == nil || a.cfg.Home.ConsumerID == "" {
18 http.NotFound(w, r)
19 return
20 }
21 var owners int
22 if err := a.db.QueryRowContext(r.Context(), `SELECT count(*) FROM members WHERE role = 'owner'`).Scan(&owners); err != nil {
23 http.Error(w, http.StatusText(http.StatusServiceUnavailable), http.StatusServiceUnavailable)
24 return
25 }
26 roster := "owner-pending"
27 if owners > 0 {
28 roster = "ok"
29 }
30 w.Header().Set("Content-Type", "application/json")
31 w.Header().Set("Cache-Control", "no-store")
32 _ = json.NewEncoder(w).Encode(struct {
33 TeamMode bool `json:"team_mode"`
34 Seeded bool `json:"seeded"`
35 Consumer string `json:"consumer"`
36 Roster string `json:"roster"`
37 }{false, true, a.cfg.Home.ConsumerID, roster})
38}
39