backive/db/db.go

30 lines
416 B
Go
Raw Normal View History

2021-10-18 22:36:54 +02:00
package db
2021-10-27 23:05:36 +02:00
import (
"encoding/json"
"os"
)
2021-10-18 22:36:54 +02:00
2021-10-27 23:05:36 +02:00
var Database map[string]string
var path string = "/var/lib/backive/data.json"
2021-10-18 22:36:54 +02:00
func Save() {
2021-10-27 23:05:36 +02:00
jsonstr, merr := json.Marshal(Database)
if merr != nil {
panic(merr)
}
2021-10-18 22:36:54 +02:00
2021-10-27 23:05:36 +02:00
err := os.WriteFile(path, []byte(jsonstr), 0644)
if err != nil {
panic(err)
}
}
func Load() {
data, err := os.ReadFile(path)
if err != nil {
panic(err)
}
json.Unmarshal(data, Database)
2021-10-18 22:36:54 +02:00
}