New creates a new empty JSONFile at the given path.
(path string)
| 26 | |
| 27 | // New creates a new empty JSONFile at the given path. |
| 28 | func New[Data any](path string) (*JSONFile[Data], error) { |
| 29 | p := &JSONFile[Data]{path: path, bytes: []byte("{}"), data: new(Data)} |
| 30 | if err := p.Write(func(*Data) error { return nil }); err != nil { |
| 31 | return nil, fmt.Errorf("jsonfile.New: %w", err) |
| 32 | } |
| 33 | return p, nil |
| 34 | } |
| 35 | |
| 36 | // Load loads an existing JSONFileData from the given path. |
| 37 | // |