Why not out of the loop?

Implement a parser for files in each folder should be fixed in 288 files, but failures do occur and a new file is created and data is written there, but the old file remains with those that signed up before the break of the work(without the data which it is necessary to put), so can't do buffiethebody channel because it is impossible to predict in advance how many files and then when reading from the channel and adding all the amount, the result is correct, but can't exit the loop, I tried different options but nothing output code is presented below.
// output byte array
 out := make(chan []byte)
 var wg sync.WaitGroup
wg.Add(threads)
 for i := 0; i < threads;i++{
 go func() {
Run(done,cmd,out)
wg.Done()
}()

}
 go func() {
wg.Wait()
close(out)
}()
 channelOctets := make(chan int64)
wg.Add(threads)
 for i:=0;i < threads;i++{
 go func() {
GetOctets(done,out,channelOctets)
wg.Done()
}()
}
 go func() {
wg.Wait()
close(channelOctets)
}()
 //not working
 for test := range channelOctets{
 Octets += test
}
 //also not out of the loop
Loop:
 for {
select{
 case octet,ok := <-channelOctets:
 if !ok{
 break Loop
}
 Octets +=octet
 case <-done:
return
}
}
fmt.Println("=================================")
fmt.Printf("%d\n",Octets)
fmt.Println("=================================")

func GetOctets(done <-chan struct{},out <-chan []byte,octets chan<- int64){

loop: for o := range out{
 first := bytes.Index(o,[]byte("Total Octets"))
 last := bytes.Index(o,[]byte("Total Packets"))
 if first == -1 || last == -1 || len(o) < minLenght{
 break loop
}
 var pattern= "[-+]?([0-9]*\\.[0-9]+|[0-9]+)"
 re := regexp.MustCompile(pattern)
 octet := re.FindAllString(string(o[first:last]),1)
 select {
 case octets <- parsetoint(octet[0]):
 case <-done:

}

}
}
func Run(done <-chan struct{},cmdCom <- chan string,result chan<- []byte){


 for c := range cmdCom{
 cmd, err := exec.Command("sh","-c",c).Output()
 if err != nil {
fmt.Println(err)
}
 select {
 case result <- cmd:
 case <-done:

}

}



}
March 23rd 20 at 19:25
0 answer

Find more questions by tags Go