refactor: clean up code and enhance utilities with new functions

This commit is contained in:
yusing
2025-03-28 08:08:33 +08:00
parent 7707fc6f36
commit cdb3ffe439
9 changed files with 103 additions and 17 deletions

View File

@@ -529,10 +529,10 @@ func SaveJSON[T any](path string, src *T, perm os.FileMode) error {
return os.WriteFile(path, data, perm)
}
func LoadJSONIfExist[T any](path string, dst *T) (exists bool, err error) {
err = loadSerialized(path, dst, json.Unmarshal)
if err != nil && os.IsNotExist(err) {
return false, nil
func LoadJSONIfExist[T any](path string, dst *T) error {
err := loadSerialized(path, dst, json.Unmarshal)
if os.IsNotExist(err) {
return nil
}
return true, err
return err
}