func remoteQueryTaxid2TaxonByFile(host string, port int, dataFile string, chunkSize int, threads int) { if chunkSize <= 0 { chunkSize = 1000 } fn := func(line string) (interface{}, bool, error) { line = strings.TrimRight(line, "\n") if line == "" { return "", false, nil } return line, true, nil } reader, err := breader.NewBufferedReader(dataFile, threads, chunkSize, fn) checkError(err) chResults := make(chan taxon.MessageTaxid2TaxonMap, threads) // receive result and print chDone := make(chan int) go func() { for msg := range chResults { if msg.Status != "OK" { log.Error(msg.Message) } for taxid, taxon := range msg.Taxons { fmt.Printf("Query TaxIDs: %s\n", taxid) bs, err := json.MarshalIndent(taxon, "", " ") checkError(err) fmt.Printf("Taxon: %s\n\n", string(bs)) } } chDone <- 1 }() // querying var wg sync.WaitGroup tokens := make(chan int, threads) for chunk := range reader.Ch { tokens <- 1 wg.Add(1) queries := make([]string, len(chunk.Data)) for i, data := range chunk.Data { queries[i] = data.(string) } go func(queries []string) { defer func() { wg.Done() <-tokens }() msg := taxon.RemoteQueryTaxid2Taxon(host, port, queries) checkError(err) chResults <- msg }(queries) } wg.Wait() close(chResults) <-chDone }
func remoteQueryTaxid2Taxon(host string, port int, taxids []string) { msg := taxon.RemoteQueryTaxid2Taxon(host, port, taxids) if msg.Status != "OK" { log.Error(msg.Message) } for taxid, taxon := range msg.Taxons { fmt.Printf("Query TaxIDs: %s\n", taxid) bs, err := json.MarshalIndent(taxon, "", " ") checkError(err) fmt.Printf("Taxon: %s\n\n", string(bs)) } }