its been a while
This commit is contained in:
1 parent
ea7470231f
commit
34f13c65e1
47 files changed
+5680
-339
No files matched your search
@@ -0,0 +1,35 @@
|
||||
package logs
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
)
|
||||
|
||||
func ReadState(path string) (map[string]SourceState, error) {
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return map[string]SourceState{}, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
out := map[string]SourceState{}
|
||||
if len(data) == 0 {
|
||||
return out, nil
|
||||
}
|
||||
if err := json.Unmarshal(data, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func WriteState(path string, state map[string]SourceState) error {
|
||||
if state == nil {
|
||||
state = map[string]SourceState{}
|
||||
}
|
||||
data, err := json.Marshal(state)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(path, data, 0o600)
|
||||
}
|
||||
Reference in new issue
Block a user