Some Doc strings

This commit is contained in:
Marcel Otte 2021-10-27 23:17:18 +02:00
parent b5f3eec03a
commit a64be87c6f
4 changed files with 20 additions and 3 deletions

View File

@ -13,21 +13,26 @@ var (
vconfig *viper.Viper
)
// Configuration struct holding the settings and config items of devices and backups
type Configuration struct {
Settings Settings `mapstructure:"settings"`
Devices Devices `mapstructure:"devices"`
Backups Backups `mapstructure:"backups"`
}
// Settings struct holds the global configuration items
type Settings struct {
SystemMountPoint string `mapstructure:"systemMountPoint"`
UserMountPoint string `mapstructure:"userMountPoint"`
}
// Devices is nothing else than a name to Device type mapping
type Devices map[string]core.Device
// Backups is nothing else than a name to Backup type mapping
type Backups map[string]core.Backup
// CreateViper creates a viper instance for usage later
func CreateViper() *viper.Viper {
vconfig := viper.New()
vconfig.SetConfigName("backive")
@ -38,6 +43,7 @@ func CreateViper() *viper.Viper {
return vconfig
}
// Load loads the configuration from the disk
func Load() *Configuration {
vconfig := CreateViper()
if err := vconfig.ReadInConfig(); err != nil {
@ -64,10 +70,12 @@ func Load() *Configuration {
return cfg
}
// Init Initializes the configuration
func Init() {
config = Load()
}
// Get returns the Configuration global variable
func Get() *Configuration {
return config
}

View File

@ -7,8 +7,10 @@ type Device struct {
OwnerUser string `mapstructure:"owner,omitempty"`
}
// Mount will mount a device
func (d Device) Mount() {
}
// Unmount will unmount a device
func (d Device) Unmount() {
}

View File

@ -5,9 +5,11 @@ import (
"os"
)
// Database is a simple string to string mapping, where arbitrary strings can be stored and safed to disk or loaded
var Database map[string]string
var path string = "/var/lib/backive/data.json"
// Save saves the database
func Save() {
jsonstr, merr := json.Marshal(Database)
if merr != nil {
@ -20,10 +22,11 @@ func Save() {
}
}
// Load loads the database
func Load() {
data, err := os.ReadFile(path)
if err != nil {
panic(err)
}
json.Unmarshal(data, Database)
json.Unmarshal(data, &Database)
}

View File

@ -8,10 +8,12 @@ import (
"github.com/qwc/backive/db"
)
// Runs contains the Data for the scheduler: mapping from backups to a list of timestamps of the last 10 backups
type Runs map[string][]time.Time
var runs Runs
// Load loads the data from the json database
func Load() {
runerr := json.Unmarshal([]byte(db.Database["runs"]), &runs)
if runerr != nil {
@ -19,6 +21,7 @@ func Load() {
}
}
// Save saves the data into the json database
func Save() {
str, err := json.Marshal(runs)
if err != nil {
@ -28,9 +31,10 @@ func Save() {
db.Database["runs"] = string(str)
}
// ShouldRun Takes a backup key and returns a bool if a backup should run now.
func ShouldRun(backup string) bool {
freq := config.Get().Backups[backup].Frequency
backupdata := config.Get().Backups[backup]
freq := backupdata.Frequency
// calculate time difference from last run, return true if no run has taken place
if freq > 0 {
return true