MCPcopy Create free account
hub / github.com/Done-0/gin-scaffold / SaveJSONFile

Function SaveJSONFile

internal/utils/file/json_utils.go:29–45  ·  view source on GitHub ↗

SaveJSONFile saves data to a JSON file with proper formatting

(filePath string, data any)

Source from the content-addressed store, hash-verified

27
28// SaveJSONFile saves data to a JSON file with proper formatting
29func SaveJSONFile(filePath string, data any) error {
30 dir := filepath.Dir(filePath)
31 if err := os.MkdirAll(dir, 0755); err != nil {
32 return fmt.Errorf("failed to create directory: %w", err)
33 }
34
35 jsonData, err := json.MarshalIndent(data, "", " ")
36 if err != nil {
37 return fmt.Errorf("failed to marshal JSON: %w", err)
38 }
39
40 if err := os.WriteFile(filePath, jsonData, 0644); err != nil {
41 return fmt.Errorf("failed to write file: %w", err)
42 }
43
44 return nil
45}
46
47// GetFileNameWithoutExt returns filename without extension
48func GetFileNameWithoutExt(filePath string) string {

Callers 2

CreateTemplateMethod · 0.92
UpdateTemplateMethod · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected