GET /version says which life-weaver release is serving (#44)
The archive service answers {"version": ...}: goreleaser's tag by
-X main.release, else the module version a go install from the proxy
carried, else (devel). serve prints it on starting.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
parent
ef6779fb17
commit
bc7ba1abe6
6 changed files with 48 additions and 8 deletions
|
|
@ -10,6 +10,8 @@ builds:
|
|||
binary: life-weaver
|
||||
env:
|
||||
- CGO_ENABLED=0
|
||||
ldflags:
|
||||
- -s -w -X main.release={{.Tag}}
|
||||
goos:
|
||||
- linux
|
||||
- darwin
|
||||
|
|
|
|||
|
|
@ -115,6 +115,7 @@ and a receipt for either.
|
|||
| `POST /people/{id}/items` | Reserve the next item id, homed with the person: `201` and the receipt, `status: reserved` |
|
||||
| `PUT /items/{item}` | Deposit for a reserved id, the body a tar holding the bag under `bag/` and each master's renditions under `renditions/<recipe>/` (`display.jpg`, `thumb.jpg`, `tiny.jpg`, `recipe.yaml` naming the master's sha256; the back's under `back/`): `201` and the receipt, `status: held`, with `payload`, the bag's manifest; `200` when the same bag is held already (its renditions stay); `400` a bag not whole or naming another id, or a refusal `renditions` (`file` is what is missing or wrong, or the master with none); `404` an id not reserved; `409` a refusal, `duplicate` (a picture in the bag is held as part of `duplicate_of`, homed with `home`) or `conflict` (the id holds a bag with other checksums). The layout is in `docs/archive.md`, *Depositing an item* |
|
||||
| `GET /items/{item}` | The receipt: `reserved`, or `held` with the manifest; `404` if there is none |
|
||||
| `GET /version` | `{"version": "v0.6.0"}`: the life-weaver release serving; `(devel)` for a local build |
|
||||
|
||||
A receipt is `{"item", "home", "status", "payload": {"data/front.tif": "<sha256>", …}}`.
|
||||
The scanner closes a batch once every photo's receipt says `held`.
|
||||
|
|
|
|||
1
changes/44.added.md
Normal file
1
changes/44.added.md
Normal file
|
|
@ -0,0 +1 @@
|
|||
- `GET /version` says which life-weaver release the archive service is, and `serve` prints it on starting (#44)
|
||||
|
|
@ -14,6 +14,7 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime/debug"
|
||||
"strconv"
|
||||
|
||||
"git.bytestone.uk/hum3/life-weaver/internal/archive"
|
||||
|
|
@ -87,8 +88,23 @@ func serve(args []string) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("%d people from %s on http://%s/people\n", len(reg.People), *dir, *addr)
|
||||
return http.ListenAndServe(*addr, archive.New(reg, items).Handler())
|
||||
fmt.Printf("life-weaver %s: %d people from %s on http://%s/people\n", version(), len(reg.People), *dir, *addr)
|
||||
return http.ListenAndServe(*addr, archive.New(reg, items, version()).Handler())
|
||||
}
|
||||
|
||||
// release is set by goreleaser (-X main.release=v…) on a binary release.
|
||||
var release string
|
||||
|
||||
// version is the release serving: goreleaser's, else the module version a
|
||||
// go install from the proxy carried, else (devel) for a local build.
|
||||
func version() string {
|
||||
if release != "" {
|
||||
return release
|
||||
}
|
||||
if bi, ok := debug.ReadBuildInfo(); ok && bi.Main.Version != "" {
|
||||
return bi.Main.Version
|
||||
}
|
||||
return "(devel)"
|
||||
}
|
||||
|
||||
func id(args []string) error {
|
||||
|
|
|
|||
|
|
@ -18,13 +18,14 @@ import (
|
|||
|
||||
// Service serves one loaded register and the archive's items.
|
||||
type Service struct {
|
||||
reg *person.Register
|
||||
items *item.Items
|
||||
reg *person.Register
|
||||
items *item.Items
|
||||
version string
|
||||
}
|
||||
|
||||
// New serves reg and items.
|
||||
func New(reg *person.Register, items *item.Items) *Service {
|
||||
return &Service{reg: reg, items: items}
|
||||
// New serves reg and items as the life-weaver release version.
|
||||
func New(reg *person.Register, items *item.Items, version string) *Service {
|
||||
return &Service{reg: reg, items: items, version: version}
|
||||
}
|
||||
|
||||
// Entry is a person as the register lists them: enough to pick one by.
|
||||
|
|
@ -46,8 +47,10 @@ type Entry struct {
|
|||
// renditions/<recipe>/: 201 held, 200 if held already with the same checksums;
|
||||
// 400 a bad bag, or a Refusal (renditions); 404 not reserved; 409 a Refusal
|
||||
// GET /items/{item} the receipt: reserved, or held with the bag's manifest
|
||||
// GET /version {"version": ...}: the life-weaver release serving
|
||||
func (s *Service) Handler() http.Handler {
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("GET /version", s.serving)
|
||||
mux.HandleFunc("GET /people", s.people)
|
||||
mux.HandleFunc("GET /people/{id}", s.person)
|
||||
mux.HandleFunc("POST /people/{id}/items", s.reserve)
|
||||
|
|
@ -69,6 +72,10 @@ type Refusal struct {
|
|||
File string `json:"file,omitempty"`
|
||||
}
|
||||
|
||||
func (s *Service) serving(w http.ResponseWriter, _ *http.Request) {
|
||||
writeJSON(w, map[string]string{"version": s.version})
|
||||
}
|
||||
|
||||
func (s *Service) reserve(w http.ResponseWriter, r *http.Request) {
|
||||
home, err := pid.Parse(r.PathValue("id"))
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ func serveWritable(t *testing.T) (*httptest.Server, string) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
srv := httptest.NewServer(New(reg, items).Handler())
|
||||
srv := httptest.NewServer(New(reg, items, "v9.9.9-test").Handler())
|
||||
t.Cleanup(srv.Close)
|
||||
return srv, root
|
||||
}
|
||||
|
|
@ -160,3 +160,16 @@ func TestOnlyGET(t *testing.T) {
|
|||
t.Errorf("POST /people: %d", resp.StatusCode)
|
||||
}
|
||||
}
|
||||
|
||||
func TestVersionSaysWhichReleaseIsServing(t *testing.T) {
|
||||
srv := serve(t)
|
||||
var got struct {
|
||||
Version string `json:"version"`
|
||||
}
|
||||
if resp := get(t, srv, "/version", &got); resp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("status %d", resp.StatusCode)
|
||||
}
|
||||
if got.Version != "v9.9.9-test" {
|
||||
t.Errorf("version %q", got.Version)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue