package main import ( "concord.hectabit.org/Hectabit/burgerbackup/lib/client" "github.com/spf13/viper" "log" "os" "strconv" "time" ) func main() { if _, err := os.Stat("config.ini"); err == nil { log.Println("[INFO] Config loaded at", time.Now().Unix()) } else if os.IsNotExist(err) { log.Fatalln("[FATAL] config.ini does not exist") } else { log.Fatalln("[FATAL] File is in quantum uncertainty:", err) } viper.SetConfigName("config") viper.AddConfigPath("./") viper.AutomaticEnv() err := viper.ReadInConfig() if err != nil { log.Fatalln("[FATAL] Error in config file at", strconv.FormatInt(time.Now().Unix(), 10)+":", err) } backupKey := viper.GetString("BACKUP_KEY") cryptoKey := viper.GetString("CRYPTO_KEY") backupInterval := viper.GetInt("BACKUP_INTERVAL") fileLocation := viper.GetString("FILE_LOCATION") remoteURL := viper.GetString("REMOTE_URL") for { err, errCode := client.PerformBackup(fileLocation, backupKey, cryptoKey, remoteURL) if err != nil { if errCode == 0 { log.Println("[CRITICAL] Unknown in performBackup() file read:", err) } else if errCode == 1 { log.Println("[CRITICAL] Unknown in performBackup() content encryption:", err) } else if errCode == 2 { log.Println("[CRITICAL] Unknown in SendFileToServer() request creation:", err) } else if errCode == 3 { log.Println("[CRITICAL] Unknown in SendFileToServer() hash creation:", err) } else if errCode == 4 { log.Println("[CRITICAL] Unknown in SendFileToServer() request execution:", err) } else if errCode == 5 { log.Println("[CRITICAL] Unknown in SendFileToServer() response read:", err) } else if errCode == 6 { log.Println("[CRITICAL] Unknown in SendFileToServer() response marshalling:", err) } else if errCode == 7 { log.Println("[CRITICAL] Server sent message in SendFileToServer():", err) } else { log.Println("[CRITICAL] Unknown error in main():", err) } } time.Sleep(time.Duration(backupInterval) * 1000000000) } }