go 管道类型,双向或单向

package main

import (
        "fmt"
        "sync"
        "time"
)

var wggg sync.WaitGroup
//申明管道类型 queue <-chan string  queue 是管道名称 <-chan 管道类型  单向管道还是双向管道 string 是申明管道中传输的数据类型  
func consumer(queue chan string){
     defer wggg.Done()
     //如果是不判断管道是否关闭,这个循环就会一直跑下去
     //for {
     // data:= <- queue
     // fmt.Println(data)
     // time.Sleep(time.Second)
         //}
        for {
                data,ok:= <- queue
                if !ok{
                        break
                }
                fmt.Println(data)
                time.Sleep(time.Second)
                //放入一个数据
                queue<-"取到返回的数据"
        }
}
func main(){
   //有没有缓存 1.有缓存的,2.无缓冲
   //双向的还是单向的 为了安全 还提供了单向的channel
        //普通通道 可以给单向通道传输数据,但单向不能给双向传输数据  chan<- 给通道写入数据   <-chan 从通道中取出数据
        var msgg chan string
        msgg=make(chan string)
        wggg.Add(1)
        go consumer(msgg)
        msgg <-"数据"// 把数据字符串加入管道中
        fmt.Println("等待返回值")
        fmt.Println(<-msgg)//取值
        close(msgg)
    wggg.Wait()
}