MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / loadJSONConfig

Function loadJSONConfig

internal/mcp/install.go:323–342  ·  view source on GitHub ↗

loadJSONConfig reads path as a JSON object. A missing or whitespace-only file is treated as an empty config (so AddPadEntry can populate from scratch on first install). Callers that need to distinguish "missing" from "empty" check os.Stat separately. Read or parse errors on a non-empty file propaga

(path string)

Source from the content-addressed store, hash-verified

321// never silently overwrite a corrupt config; the user has to fix or
322// remove it.
323func loadJSONConfig(path string) (map[string]any, error) {
324 b, err := os.ReadFile(path)
325 if errors.Is(err, os.ErrNotExist) {
326 return map[string]any{}, nil
327 }
328 if err != nil {
329 return nil, fmt.Errorf("read %s: %w", path, err)
330 }
331 if isAllWhitespace(b) {
332 return map[string]any{}, nil
333 }
334 var raw map[string]any
335 if err := json.Unmarshal(b, &raw); err != nil {
336 return nil, fmt.Errorf("parse %s: %w", path, err)
337 }
338 if raw == nil {
339 raw = map[string]any{}
340 }
341 return raw, nil
342}
343
344func isAllWhitespace(b []byte) bool {
345 for _, c := range b {

Callers 3

AddPadEntryFunction · 0.85
RemovePadEntryFunction · 0.85
HasPadEntryFunction · 0.85

Calls 1

isAllWhitespaceFunction · 0.85

Tested by

no test coverage detected