40 lines
1.3 KiB
Go
40 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"sort"
|
|
|
|
sweep "git.novox.be/novox/mesh-delivery/contracts/go/seats/meshartifactsweep"
|
|
)
|
|
|
|
// The holders whose states this module reads, one constant each (a reader names its holder once; ADR 0634 §4).
|
|
const (
|
|
assignerModule = "mesh-delivery-assigner"
|
|
indexerModule = "mesh-delivery-indexer"
|
|
)
|
|
|
|
// The seat mesh-artifact-sweep types the answer of its verb held and the body of its event artifacts-gone; this module
|
|
// holds the seat, so it answers and says them in those types.
|
|
type (
|
|
// HeldAnswer is the answer of the seat's verb held.
|
|
HeldAnswer = sweep.HeldAnswer
|
|
// ArtifactsGone is the body of the seat's event artifacts-gone.
|
|
ArtifactsGone = sweep.ArtifactsGone
|
|
)
|
|
|
|
// GoneSubject is where the seat says artifacts-gone.
|
|
const GoneSubject = sweep.SubjectArtifactsGone
|
|
|
|
// EncodeArtifactsGone is the event's body, the references sorted; it refuses one naming no module, no fingerprint or no
|
|
// gone reference.
|
|
func EncodeArtifactsGone(e ArtifactsGone) ([]byte, error) {
|
|
e.Event = sweep.EventArtifactsGone
|
|
e.Gone = append([]string(nil), e.Gone...)
|
|
sort.Strings(e.Gone)
|
|
if e.Module == "" || e.Fingerprint == "" || len(e.Gone) == 0 {
|
|
return nil, fmt.Errorf("%s names a module, a fingerprint and at least one gone reference", sweep.EventArtifactsGone)
|
|
}
|
|
return json.Marshal(e)
|
|
}
|