package main import ( "database/sql" _ "github.com/go-sql-driver/mysql" "log" "os" "time" ) var ( flogger *log.Logger ) func init() { flogger = log.New(os.Stdout, "[ Flow-cleaner ]", log.LstdFlags) } func main() { cfg, err := readConfig() if err != nil { flogger.Println("Could not read config") return } switch cfg.DataSource { case "stdin": processFromStdin(cfg) case "mysq": processFromDB(cfg) default: flogger.Println("Invalid dataSource in config. Needs to be either 'stdin' or 'mysql'.") } flogger.Println("Finished processing, now exiting") } func processFromStdin(cfg *Config) { flogger.Println("Starting to process from stdin...") input := readFromStdin() rDatChan := parseRawData(input, cfg) err := cleanFromStdin(rDatChan, cfg) if err != nil { flogger.Println("Failed to clean data:", err) } flogger.Println("Finished processing from stdin!") } func processFromDB(cfg *Config) { flogger.Print("Starting to process from db...") starttime := time.Now() numOfRowsNotCleaned, err := cleanFromDB(cfg) if err != nil { flogger.Println(err) flogger.Println("Exiting...") return } flogger.Println("Finished processing from db!") // If either all rows are processed or if there is no limit for the processing // we can safely add noise to the cleaned data if (numOfRowsNotCleaned == 0 || cfg.Limit == 0) && cfg.Epsilon >= 0 { flogger.Println("Adding differential privacy noise to processed data...") db, err := sql.Open("mysql", cfg.DBUser+":"+cfg.DBPass+"@"+cfg.DBConn+"/"+cfg.DBName) if err != nil { flogger.Println("Failed to connect to db:", err) return } defer db.Close() ival, err := cfg.getInterval() if err != nil { flogger.Println("erronous interval in conf prevents the privatization of data:", err) return } err = privatizeCleaned(db, starttime.Add(-2*ival), cfg) if err != nil { flogger.Println("Failed to privatize data:", err) } flogger.Println("Done!") } }