little restructuring

This commit is contained in:
Marcel Otte 2021-10-27 23:05:36 +02:00
parent 8af0f45ab0
commit b5f3eec03a
6 changed files with 65 additions and 5 deletions

2
.gitignore vendored
View File

@ -15,4 +15,6 @@
# vendor/
example
*.vim
dist/

View File

@ -1 +0,0 @@
package core

View File

@ -1 +0,0 @@
package core

View File

@ -1,10 +1,29 @@
package db
import "encoding/json"
import (
"encoding/json"
"os"
)
var database map[string]string
var Database map[string]string
var path string = "/var/lib/backive/data.json"
func Save() {
jsonstr := json.Marshal(database)
jsonstr, merr := json.Marshal(Database)
if merr != nil {
panic(merr)
}
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)
}

1
events/events.go Normal file
View File

@ -0,0 +1 @@
package events

40
scheduler/scheduler.go Normal file
View File

@ -0,0 +1,40 @@
package scheduler
import (
"encoding/json"
"time"
"github.com/qwc/backive/config"
"github.com/qwc/backive/db"
)
type Runs map[string][]time.Time
var runs Runs
func Load() {
runerr := json.Unmarshal([]byte(db.Database["runs"]), &runs)
if runerr != nil {
panic(runerr)
}
}
func Save() {
str, err := json.Marshal(runs)
if err != nil {
panic(err)
}
db.Database["runs"] = string(str)
}
func ShouldRun(backup string) bool {
freq := config.Get().Backups[backup].Frequency
// calculate time difference from last run, return true if no run has taken place
if freq > 0 {
return true
}
return false
}