fix(storage): initialize file to an empty JSON

It will avoir error message like `time="2022-11-14T01:40:49Z" level=error msg="error loading sessionsEOF"`
This commit is contained in:
Alexis Couvreur
2022-11-14 15:15:22 +00:00
parent fc9e1fa8d2
commit 80f2304375
2 changed files with 10 additions and 1 deletions

View File

@@ -33,6 +33,16 @@ func NewFileStorage(config config.Storage) (Storage, error) {
}
defer file.Close()
stats, err := file.Stat()
if err != nil {
return nil, err
}
// Initialize file to an empty JSON3
if stats.Size() == 0 {
file.WriteString("{}")
}
log.Infof("initialized storage to %s", config.File)
} else {
log.Warn("no storage configuration provided. all states will be lost upon exit")

View File

@@ -189,7 +189,6 @@
time="2022-11-14T01:40:49Z" level=info msg="(version=1.1.1, branch=HEAD, revision=a913bc2a3b0f4aca5b9ac7ddc9af5428ef411dba)"
time="2022-11-14T01:40:49Z" level=info msg="using provider \"kubernetes\""
time="2022-11-14T01:40:49Z" level=info msg="initialized storage to /etc/sablier/state.json"
time="2022-11-14T01:40:49Z" level=error msg="error loading sessionsEOF"
time="2022-11-14T01:40:49Z" level=info msg="server listening :10000"
```