(ns namespace)
| 49 | } |
| 50 | |
| 51 | func 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 | |
| 78 | func save() error { |
| 79 | errs := gperr.NewBuilder("failed to save data stores") |
nothing calls this directly
no test coverage detected