1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package local
import (
"encoding/json"
"fmt"
"os"
"github.com/johnandersen777/socialweb-computer-kcp/internal/contract/lease"
)
type (
Slot = lease.Slot
Slots = lease.Slots
)
type SlotFile struct {
Path string
}
func (f SlotFile) Slots() (Slots, error) {
b, err := os.ReadFile(f.Path)
if err != nil {
return Slots{}, err
}
var s Slots
if err := json.Unmarshal(b, &s); err != nil {
return Slots{}, fmt.Errorf("local: %s: %w", f.Path, err)
}
if s.Slots == nil {
s.Slots = map[string]Slot{}
}
return s, nil
}