惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
V
Vulnerabilities – Threatpost
B
Blog
月光博客
月光博客
宝玉的分享
宝玉的分享
有赞技术团队
有赞技术团队
美团技术团队
IT之家
IT之家
B
Blog RSS Feed
V
V2EX
Hugging Face - Blog
Hugging Face - Blog
T
The Blog of Author Tim Ferriss
Vercel News
Vercel News
Jina AI
Jina AI
Y
Y Combinator Blog
Recorded Future
Recorded Future
N
Netflix TechBlog - Medium
S
SegmentFault 最新的问题
L
LangChain Blog
博客园 - 聂微东
人人都是产品经理
人人都是产品经理
PCI Perspectives
PCI Perspectives
Schneier on Security
Schneier on Security
Microsoft Azure Blog
Microsoft Azure Blog
P
Privacy International News Feed
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
C
Cyber Attacks, Cyber Crime and Cyber Security
N
News and Events Feed by Topic
W
WeLiveSecurity
L
Lohrmann on Cybersecurity
Security Archives - TechRepublic
Security Archives - TechRepublic
Help Net Security
Help Net Security
Google DeepMind News
Google DeepMind News
P
Proofpoint News Feed
S
Schneier on Security
Last Week in AI
Last Week in AI
L
LINUX DO - 最新话题
Webroot Blog
Webroot Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
云风的 BLOG
云风的 BLOG
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More
C
CXSECURITY Database RSS Feed - CXSecurity.com
J
Java Code Geeks
T
Threatpost
腾讯CDC
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
T
The Exploit Database - CXSecurity.com
H
Help Net Security

博客园 - Leepy

AI应用平台搭建之旅(上) - 框架篇(附:AICon大会阿里国际Agent应用平台分享) 阿里巴巴LangEngine开源了!支撑亿级网关规模的高可用Java原生AI应用开发框架 iOS学习系列 - 标签Tag列表的实现 iOS学习系列 - UITableView下拉更新/上提加载的实现 iOS学习系列 - MonoTouch绑定原生Obj-C静态库的实现 iOS学习系列 - 在iOS客户端实现google oauth2登录以及在asp.net服务端上form认证 iOS学习系列 - 利用ASIHTTPRequest实现异步队列 iOS学习系列 - 扩展机制category与associative Wind.js在移动跨平台框架PhoneGap中的异步体验 Mono for Andriod学习与实践(1)— 初体验 阿里技术嘉年华官网上线啦! Silverlight实现对Sql Server Profiler的SQL实时监控 利用Mono.Cecil动态修改程序集来破解商业组件(仅用于研究学习) Silverlight 4以下版本模拟鼠标双击事件 利用Nginx+Mono+Fastcgi代替IIS对Asp.Net进行反向代理 Thrift初探:简单实现C#通讯服务程序 对于.Net中C#指针的研究 各大主流.Net的IOC框架性能测试比较 依赖注入框架Autofac的简单使用
在mac上安装Go语言初体验
Leepy · 2012-11-08 · via 博客园 - Leepy

我将在mac os x的开发机器上安装go语言的开发环境。

go语言运行包下载地址:http://code.google.com/p/go/downloads/list

这里我选择安装 go1.0.3.darwin-amd64.pkg

在mac上点击安装,运行包自动安装到/usr/local/go中,这样在命令终端就可以运行go命令了

这里,我把go编辑器安装到我的xcode应用程序中,由于我的xcode装的是4.x以上

在/usr/local/go/misc中,可以看到有很多编辑器版本,这里找到xcode目录,里面进入4,有个go4xcode.sh

在终端中输入:

也许有的,你会报以下这样的错误:

xcrun: Error: could not stat active Xcode path '/Volumes/Xcode/Xcode44-DP7.app/Contents/Developer'. (No such file or directory)

可以查看这个解决方法:http://stackoverflow.com/questions/11456918/change-xcrun-developer-path

通过xcode-select命令来解决。

默认mac上安装go运行包,不会添加GOROOT的环境变量,你必须加上一个GOROOT为/usr/local/go的目录,这样再执行go4xcode.sh的时候就不会出现错误。

现在引用一个socket通信样例:

server

package main
 
import (
    "net"
    "fmt"
    "io"
)
 
const RECV_BUF_LEN = 1024
 
func main() {
    listener, err := net.Listen("tcp""0.0.0.0:6666")//侦听在6666端口
    if err != nil {
        panic("error listening:"+err.Error())
    }
    fmt.Println("Starting the server")
 
    for {
        conn, err := listener.Accept() //接受连接
        if err != nil {
            panic("Error accept:"+err.Error())
        }
        fmt.Println("Accepted the Connection :", conn.RemoteAddr())
        go EchoServer(conn)
    }
}
 
func EchoServer(conn net.Conn) {
    buf := make([]byte, RECV_BUF_LEN)
    defer conn.Close()
 
    for {
        n, err := conn.Read(buf);
        switch err {
            case nil:
                conn.Write( buf[0:n] )
            case io.EOF:
                fmt.Printf("Warning: End of data: %s \n", err);
                return
            default:
                fmt.Printf("Error: Reading data : %s \n", err);
                return
        }
     }
}

client

package main
 
import (
    "fmt"
    "time"
    "net"
)
 
const RECV_BUF_LEN = 1024
 
func main() {
    conn,err := net.Dial("tcp""127.0.0.1:6666")
    if err != nil {
        panic(err.Error())
    }
    defer conn.Close()
 
    buf := make([]byte, RECV_BUF_LEN)
 
    for i := 0; i < 5; i++ {
        //准备要发送的字符串
        msg := fmt.Sprintf("Hello World, %03d", i)
        n, err := conn.Write([]byte(msg))
        if err != nil {
            println("Write Buffer Error:", err.Error())
            break
        }
        fmt.Println(msg)
 
        //从服务器端收字符串
        n, err = conn.Read(buf)
        if err !=nil {
            println("Read Buffer Error:", err.Error())
            break
        }
        fmt.Println(string(buf[0:n]))
 
        //等一秒钟
        time.Sleep(time.Second)
    }
}

先执行server:

再执行client:

回过来看server端:

当client信息发送结束后,会在server段显示 EOF结束的字符。

另外,执行go build xxx.go在当前目录下会产生一个unit可执行文件,执行./xxx 即可执行文件。