func main() { k := flag.Int("n", 500, "k") f := flag.String("f", "", "file to read") counts := flag.Bool("c", false, "each item has a count associated with it") flag.Parse() var r io.Reader if *f == "" { r = os.Stdin } else { var err error r, err = os.Open(*f) if err != nil { log.Fatal(err) } } tk := topk.New(*k) sc := bufio.NewScanner(r) for sc.Scan() { line := sc.Text() var count int var item string if *counts { fields := strings.Fields(line) cint, err := strconv.Atoi(fields[1]) if err != nil { log.Println("failed to parse count: ", fields[1], ":", err) continue } item = fields[0] count = cint } else { item = line count = 1 } err := tk.Insert(item, count) if err != nil { utils.GetLogger().Error.Println(err) } } if err := sc.Err(); err != nil { log.Fatal(err) } for _, v := range tk.Keys() { fmt.Println(v.Key, v.Count, v.Error) } }
package main import ( "flag" "os" "strconv" "github.com/seiflotfy/skizze/config" "github.com/seiflotfy/skizze/server" "github.com/seiflotfy/skizze/utils" ) var logger = utils.GetLogger() func main() { var port uint flag.UintVar(&port, "p", 3596, "specifies the port for Counts to run on") flag.Parse() //TODO: Add arguments for dataDir and infoDir os.Setenv("COUNTS_PORT", strconv.Itoa(int(port))) logger.Info.Println("Starting counts...") conf := config.GetConfig() logger.Info.Println("Using data dir: ", conf.GetDataDir()) server, err := server.New() if err != nil { panic(err) } server.Run()