go语言在idear怎么进行多个文件的链接

Python016

go语言在idear怎么进行多个文件的链接,第1张

1、解压压缩包到go工作目录,如解压到E:\opensource\go\go,解压后的目录结构如下:E:\opensource\go\go├─api├─bin│├─go.exe│├─godoc.exe│└─gofmt.exe├─doc├─include├─lib├─misc├─pkg├─src└─test2、增加环境变量GOROOT,取值为上面的go工作目录3、Path环境变量中添加"%GOROOT%\bin",以便能够直接调用go命令来编译go代码,至此go编译环境就配置好了注:如果不想手动设置系统环境变量,也可下载go启动环境批处理附件,修改goenv.bat文件中的GOROOT值为上面的go工作目录后直接双击该bat文件,go编译环境变量即设置完成。4、测试go编译环境,启动一个cmd窗口,直接输入go,看到下面的提示就是搭建成功了E:\opensource\go\go>goGoisatoolformanagingGosourcecode.Usage:gocommand[arguments]Thecommandsare:buildcompilepackagesanddependenciescleanremoveobjectfilesdocrungodoconpackagesourcesenvprintGoenvironmentinformationfixrungotoolfixonpackagesfmtrungofmtonpackagesourcesgetdownloadandinstallpackagesanddependenciesinstallcompileandinstallpackagesanddependencieslistlistpackagesruncompileandrunGoprogramtesttestpackagestoolrunspecifiedgotoolversionprintGoversionvetrungotoolvetonpackagesUse"gohelp[command]"formoreinformationaboutacommand.Additionalhelptopics:gopathGOPATHenvironmentvariablepackagesdescriptionofpackagelistsremoteremoteimportpathsyntaxtestflagdescriptionoftestingflagstestfuncdescriptionoftestingfunctionsUse"gohelp[topic]"formoreinformationaboutthattopic.5、编译helloworld测试程序,go语言包中test目录带有helloworld.go测试程序,源码见"附一helloworld.go",直接调用"gobuildhelloworld.go"就生成了"helloworld.exe"可执行程序,运行一下这个程序看到了我们期望的hello,wolrd。E:\opensource\go\go\test>gobuildhelloworld.goE:\opensource\go\go\test>helloworld.exehello,worldE:\opensource\go\go\test>附一helloworld.go//cmpout//Copyright2009TheGoAuthors.Allrightsreserved.//UseofthissourcecodeisgovernedbyaBSD-style//licensethatcanbefoundintheLICENSEfile.//Testthatwecandopage1oftheCbook.packagemainfuncmain(){print("hello,world\n")}

我们在mian函数中,首先初始化配置文件,然后新建http连接。

这个连接创建之后,监听服务器的9999端口。如果url的路径后缀为 "/ws",就转发到ws/ws.go中的IndexHandler方法中。

这个方法中首先我们创建一个websocket的Upgrader实例,然后我们使用Upgrader的upgrade方法来升级一下我们的连接为长连接。

升级完成之后会返回一个*websocket.Conn的连接,我们之后所有的关于连接的操作,都是基于该conn的。

在该连接完成之后,我们将连接存放到一个名为Client的map中,以便之后管理更为方便。

之后,我们启动一个goroutine来读取连接中发送的信息内容,再根据内容进行相应的操作。

brew install go

输入 brew info go 或者 go env 即可查看当前安装的golang版本信息

注意:千万不要把GOPATH设置成go的安装路径,可以自己在用户目录下创建一个目录,例如mygo

一般安装好go之后,使用go env查看一下当前环境。此时显示出来的GOROOT就是你使用brew安装go的安装目录,这个路径要记下来。接下来要在bash_profile文件中进行配置。

使用vim ~/.bash_profile

然后在这个文件中进行编辑,下面以我的电脑为例,路径这种要根据不同人的情况而定

GOROOT=/usr/local/Cellar/go/1.10.1/libexec (改成自己的go安装目录 go env命令可查看)

export GOROOT (不用动)

export GOPATH=/Users/jiangqiaowei/mygo (创建一个自己的文件夹 管理go相关内容)

export GOBIN=$GOPATH/bin (不用改)

export PATH=$PATH:$GOBIN:$GOROOT/bin (不用改)

$ go get golang.org/x/mobile/cmd/gomobile (需要墙)

gomobile init

$ go get -d golang.org/x/mobile/example/bind/...

$ cd $GOPATH/src/golang.org/x/mobile/example/bind

$ gomobile bind -target=ios golang.org/x/mobile/example/bind/hello

此命令在ios/路径下生成bind.xcodeprojxcode项目以及 在bind/目录下生成一个 hello.framework

拖入项目即可使用