MCPcopy Create free account
hub / github.com/GoMudEngine/GoMud / loadItemFileFromFS

Function loadItemFileFromFS

internal/items/plugin.go:68–99  ·  view source on GitHub ↗
(subFS fs.ReadFileFS, path string, dst map[int]*ItemSpec)

Source from the content-addressed store, hash-verified

66}
67
68func loadItemFileFromFS(subFS fs.ReadFileFS, path string, dst map[int]*ItemSpec) {
69 b, err := subFS.ReadFile(path)
70 if err != nil {
71 mudlog.Error("items.loadItemsFromFS", "path", path, "error", err)
72 return
73 }
74
75 var spec ItemSpec
76 if err := yaml.Unmarshal(b, &spec); err != nil {
77 mudlog.Error("items.loadItemsFromFS", "path", path, "error", err)
78 return
79 }
80
81 // Validate the Filepath() claim matches the actual path so the same
82 // rules as the disk loader apply.
83 if !strings.HasSuffix(path, spec.Filepath()) {
84 mudlog.Error("items.loadItemsFromFS", "path", path, "expected suffix", spec.Filepath(), "error", "filepath mismatch")
85 return
86 }
87
88 if err := spec.Validate(); err != nil {
89 mudlog.Error("items.loadItemsFromFS", "path", path, "error", err)
90 return
91 }
92
93 if _, exists := dst[spec.ItemId]; exists {
94 mudlog.Error("items.loadItemsFromFS", "itemId", spec.ItemId, "path", path, "error", "duplicate item id")
95 return
96 }
97
98 dst[spec.ItemId] = &spec
99}

Callers 1

loadItemsFromFSFunction · 0.85

Calls 4

FilepathMethod · 0.95
ValidateMethod · 0.95
ErrorFunction · 0.92
ReadFileMethod · 0.45

Tested by

no test coverage detected