package main import ( "bufio" "database/sql" _ "github.com/go-sql-driver/mysql" "log" "os" "time" //"strings" ) const ( DATABASE_USER = "flowcleaner" DATABASE_PASS = "nil" DATABASE_CONNECTION = "" //e.g. "tcp(localhost:55555) DATABASE_NAME = "pmacct" ) func main() { conf, err := readConfig() if err != nil { log.Println("Could not read config") return } /* stdin := readFromStdin() for line := range stdin { strs := strings.Split(line, ",") for _, str := range strs { log.Println(str) } } */ starttime := time.Now() numOfRowsNotCleaned, err := cleanData(conf, DATABASE_USER, DATABASE_PASS, DATABASE_CONNECTION, DATABASE_NAME) if err != nil { log.Println(err) } // 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 || conf.Limit == 0 { db, err := sql.Open("mysql", DATABASE_USER+":"+DATABASE_PASS+"@"+DATABASE_CONNECTION+"/"+DATABASE_NAME) if err != nil { log.Println("Failed to connect to db") return } defer db.Close() ival, err := conf.getInterval() if err != nil { log.Println("erronous interval in conf prevents the privatization of data") return } privatizeCleaned(db, starttime.Add(-2*ival), conf) } } //Starts a process that reads from stdin and //puts the strings read on the returned channel func readFromStdin() <-chan string { out := make(chan string) go func() { scanner := bufio.NewScanner(os.Stdin) for scanner.Scan() { out <- scanner.Text() } close(out) }() return out }