Go基本语法及类型理解

【论坛、网站】:

  http://studygolang.com/

  http://golangtc.com/

  https://golang.org/

 

 

 

一、数组及Slice

  参考:http://www.jb51.net/article/57121.htm

 

二、go func问题 及 defer

 

func Server(listen *net.TCPListener) {
    for {
        conn, err := listen.AcceptTCP()
        if err != nil {
            fmt.Println("AcceptTCP_Err:", err.Error())
            continue
        }
        fmt.Println("AcceptTCP_From:", conn.RemoteAddr().String())
        defer conn.Close()
        go func() {
            data := make([]byte, 128)
            for {
                i, err := conn.Read(data)
                fmt.Println("AcceptTCP_data:", string(data[0:i]))
                if err != nil {
                    fmt.Println("AcceptTCP_ReadErr:", err.Error())
                    break
                }
                conn.Write([]byte{'f', 'i', 'n', 'i', 's', 'h'})
            }

        }()
    }
}

相应理解参考:http://www.golangtc.com/t/563aeffbb09ecc3197000015

       http://blog.csdn.net/eclipser1987/article/details/12089271

 

posted @ 2016-05-19 14:47  海之涯2008  阅读(282)  评论(0编辑  收藏  举报