Add shared metadata maps and stage-name helpers
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -28,6 +29,15 @@ type Schema struct {
|
||||
SHA256 string `json:"sha256"`
|
||||
}
|
||||
|
||||
func (s Schema) DiagnosticsMap() map[string]any {
|
||||
return map[string]any{
|
||||
"id": s.ID,
|
||||
"version": s.Version,
|
||||
"name": s.Name,
|
||||
"sha256": s.SHA256,
|
||||
}
|
||||
}
|
||||
|
||||
var registry = map[Key]Schema{
|
||||
CorrectionSetKey: mustBuildSchema(
|
||||
correctionSetSchemaID,
|
||||
@@ -43,6 +53,20 @@ var registry = map[Key]Schema{
|
||||
),
|
||||
}
|
||||
|
||||
func Registered() []Schema {
|
||||
keys := make([]string, 0, len(registry))
|
||||
for key := range registry {
|
||||
keys = append(keys, string(key))
|
||||
}
|
||||
sort.Strings(keys)
|
||||
|
||||
out := make([]Schema, 0, len(keys))
|
||||
for _, key := range keys {
|
||||
out = append(out, cloneSchema(registry[Key(key)]))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// Lookup returns a copy of the registered schema for the provided key.
|
||||
func Lookup(key Key) (Schema, bool) {
|
||||
schema, ok := registry[key]
|
||||
|
||||
Reference in New Issue
Block a user