github.com/qiuhoude/go-web@v0.0.0-20220223060959-ab545e78f20d/logdir/main.go (about) 1 package main 2 3 import ( 4 "bufio" 5 "fmt" 6 "os" 7 ) 8 9 type closeer struct { 10 a int 11 b string 12 } 13 14 func main() { 15 16 ch := make(chan closeer) 17 18 for i := 0; i < 10; i++ { 19 id := i 20 go func() { 21 defer func() { 22 fmt.Printf("end goroutineId:%d\n", id) 23 }() 24 select { 25 case data := <-ch: 26 fmt.Printf("recve goroutineId:%d, data:%v \n", id, data) 27 return 28 } 29 }() 30 } 31 //ch <- struct{}{} 32 33 fmt.Println("send") 34 _, _ = bufio.NewReader(os.Stdin).ReadString('\n') 35 close(ch) 36 _, _ = bufio.NewReader(os.Stdin).ReadString('\n') 37 }