MCPcopy
hub / github.com/yusing/godoxy / loadNS

Function loadNS

internal/jsonstore/jsonstore.go:51–76  ·  view source on GitHub ↗
(ns namespace)

Source from the content-addressed store, hash-verified

49}
50
51func loadNS[T store](ns namespace) T {
52 store := reflect.New(reflect.TypeFor[T]().Elem()).Interface().(T)
53 store.Initialize()
54
55 path := filepath.Join(storesPath, string(ns)+".json")
56 file, err := os.Open(path)
57 if err != nil {
58 if !os.IsNotExist(err) {
59 log.Err(err).
60 Str("path", path).
61 Msg("failed to load store")
62 }
63 } else {
64 defer file.Close()
65 if err := strutils.NewJSONDecoder(file).Decode(&store); err != nil {
66 log.Err(err).
67 Str("path", path).
68 Msg("failed to load store")
69 }
70 }
71 log.Debug().
72 Str("namespace", string(ns)).
73 Str("path", path).
74 Msg("loaded store")
75 return store
76}
77
78func save() error {
79 errs := gperr.NewBuilder("failed to save data stores")

Callers

nothing calls this directly

Calls 4

NewMethod · 0.80
ErrMethod · 0.80
InitializeMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected