Programming in Go (Golang) – Setting up a Mac OS X Development Environment
http://www.distilnetworks.com/setup-go-golang-ide-for-mac-os-x/#.V1Byrf50yM8
Programming in Go (Golang) – Setting up a Mac OS X Development Environment
Published on February 4, 2015
At Distil, we have recently started to use Go (Golang) to expand the functionality of our data platform. A surprisingly challenging aspect of getting started with Go was setting up a development environment on my MacBook. We learned a few things along the way and hopefully information below will help you as you setup your Go development environment.
Project Workspace
The GOPATH environment variable is a key component to building Go applications. There are several approaches to manage your project workspace and external package dependencies using the $GOPATH. We decided to have one GOPATH based on the conventions in “How To Write Go Code”. For example, here are my .profile settings:
### Go
export GOROOT=/usr/local/Cellar/go/1.3.3/libexec
export PATH=$PATH:$GOROOT
GOPATH=$HOME/distil/projects/go
export PATH=$PATH:$GOPATH/bin
We use GitHub and each Go project has a separate repository. If the Go project requires multiple application binaries, we organize those under a separate folders. This was inspired by Brad Fitzpatrick’s Camlistore project. Below is an example of the Go directory layout based on the GOPATH above:
~/distil/projects/go/src/github.com/distil/
project1/
cmd/
app1/
main.go
app2/
main.go
models/
customer/
customer.go
pkg/
aws/
s3.go
ec2.go
db/
postgres/
postgres.go
project2/
Dependency Management
A variety of package managers have been built to help with Go dependency management. I would encourage you experiment to see what works best for you and your organization, but we wanted to keep things simple. We use the gpmtool which allows you to version external packages through the use of a Godeps file. Each of our projects have their own Godeps file and the dependencies are installed locally based on the single GOPATH described above. The only caveat is that running `gpm install` for different projects with conflicting versions of the same package in the Godeps file will overwrite that package locally. This is manageable as long as you update the dependencies for a project when you switch between projects.
Golang Mac IDE vs Editor
Using an IDE for Go is entirely optional and a personal preference. All you really need is a text editor and a terminal. The trick is finding the right tool(s) which allow you to be productive and efficient. If you are accustomed to using tools like RubyMine, IntelliJ or Eclipse, you will likely find it disappointing there are no equivalent, full-featured IDEs for Go. So what’s the best IDE for Golang? After trying several options which included LiteIDE, IntelliJ Go Plugin, Go-IDE and Atom, I personally settled on using Sublime Text and iTerm.
Sublime Text
Sublime Text 3 along with the GoSublime package provides several features to improve Go programming productivity. I also setup a Sublime Project for each of my Go projects which contains a sublime-project file and sublime-workspace file. If your project needs specific environment variables you can set those in your sublime-project file by adding the following:
{
"settings": {
"GoSublime": {
"env": {
"APP1_ENV": "test",
"APP1_HOME": "/var/app1"
}
}
}
}
When getting started with Sublime, I stubbled upon the Get Go-ing with Sublime post by Tyler Bunnell which contains several tips and tricks when using Sublime and GoSublime. If you decide to use Sublime, I encourage you to check out Tyler’s post. The best tip is customizing the preferences to run `go build` and `go test` upon saving a go file which I slightly modified. Below are the Gosublime preferences I use:
{
"on_save": [
{
"cmd": "gs9o_open",
"args": {
"run": [
"sh",
"go build && go test -i && go test && go fmt && go vet"
],
"focus_view": false
}
}
],
"autocomplete_closures": true,
"complete_builtins": true,
"fmt_cmd": [
"goimports"
]
}
In addition to using the GoSublime package, I also use the SublimeGit and GitGutter packages to interact with GitHub. When I am ready to run my application, I use iTerm2 instead of trying to run in the GoSublime console. Sublime Text along with the numerous packages provide a ton of shortcuts and features to improve productivity.
Setting up my current Go development environment did not happen overnight. In fact, I spent numerous hours researching and evaluating different tools, best practices and conventions. I encourage you to find a setup that works best for you and hopefully this information will save you a couple of hours!
Programming in Go (Golang) – Setting up a Mac OS X Development Environment的更多相关文章
- Mac OS X下环境搭建 Sublime Text 2 环境变量配置 开发工具配置Golang (Go语言)
Golang (Go语言) Mac OS X下环境搭建 环境变量配置 开发工具配置 Sublime Text 2 一.安装Golang的SDK 在官网http://golang.org/ 直接下载安装 ...
- COCOA® PROGRAMMING FOR MAC® OS X (1)- Get Start
这个是Mac OS App开发学习的第一篇,希望是一个好的开始. 一.为什么要学习Mac OS App开发 a)长时间做IOS开发,发现自己所做的局限在苹果的一些库上面,一些底层的API却是私有的,不 ...
- [转]“WARNING: soft rlimits too low” in MongoDB with Mac OS X
转自:Programming and Technology If you get this warning when you connect to mongo shell in Mac OX X: * ...
- Mac OS 使用 Vagrant 管理虚拟机(VirtualBox)
Vagrant(官网.github)是一款构建虚拟开发环境的工具,支持 Window,Linux,Mac OS,Vagrant 中的 Boxes 概念类似于 Docker(实质是不同的),你可以把它看 ...
- Mac OS、Ubuntu 安装及使用 Consul
Consul 概念(摘录): Consul 是 HashiCorp 公司推出的开源工具,用于实现分布式系统的服务发现与配置.与其他分布式服务注册与发现的方案,比如 Airbnb 的 SmartStac ...
- Mac OS X 上安装 ASP.NET 5
在Mac OS X Yosemite 10.10.3 中搭建第一个 ASP.NET 5 Web 项目 终于有时间在 Mac 上安装一下 ASP.NET 5,网上有许多教程,但是多数的时间比较早了,版本 ...
- 在Mac OS X Yosemite 10.10.3 中搭建第一个 ASP.NET 5 Web 项目
终于有时间在 Mac 上安装一下 ASP.NET 5,网上有许多教程,但是多数的时间比较早了,版本不是最新,搭着 Build 2015 的春风,我也实践一下 Mac OS X 上的 ASP.NET 5 ...
- MAC OS VPN使用指南
L2TP/IPSec VPN - Mac OS 使用指南 一.打开Mac的联网设置. 二.然后点左边的加号,添加新的连接. 三.选择VPN(L2TP),点击创建(Create). 四.输入你购买的VP ...
- Mac OS X 背后的故事
Mac OS X 背后的故事 作者: 王越 来源: <程序员> 发布时间: 2013-01-22 10:55 阅读: 25840 次 推荐: 49 原文链接 [收藏] ...
随机推荐
- canvas应用-思维导图
canvas应用例子-思维导图 效果图如下: 函数说明: // 求圆上一点坐标,返回坐标点 function circlePoint(x, y, r, a) { var tmpx = x + r * ...
- C语言函数可变长度参数剖析
C语言中的很多函数的入参被定义为可变参数,最典型的 int printf (const char * fmt, ...) 要对其中的可变参数进行处理,就要用到va_list类型和 VA_START, ...
- Windows Tomcat7.0 安装 Solr
准备工作 1.下载Tomcat7.0 ,apache-tomcat-7.0.67.exe,安装目录如下:C:\workspace\Tomcat7.0\ 2.下载Solr 5.2,solr-5.2.0. ...
- [AX 2012] Woker user request
在HR模块和System administrator模块下都能找到Woker user request这个功能,它的作用是为员工创建一个AX账号.比如我们创建一个这样的user request: 注意 ...
- Moto G 通话没声音
入手了摩托罗拉被 Google 收购后推出的第二款手机 Moto G (第一款是 Moto X) 后发现有个问题,有时候会莫名其妙地通话没声音,你听不到对方的,对方也听不到你的,从网上的搜索结果来看, ...
- 参照nopCommerce框架开发(NextCMS)
很久没有更新博客了,现在已经不写.NET,转前端半年多了. 半年前在创业公司,做电子商务网站,用的是NopCommerce框架(3.2),这个框架还是相当不错的,经过一段时间的摸索,基本入门,于是就开 ...
- NFS挂载Android文件系统
NFS挂载Android文件系统 [日期:2012-02-14] 来源:Linux社区 作者:cjok376240497 [字体:大 中 小] 1.安装NFS服务 $sudo apt-get ...
- BZOJ 1001 [BeiJing2006] 狼抓兔子(平面图最大流)
题目大意 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的.而且现在的兔子还比较笨,它们只有两个窝,现在你做为狼王,面对下面这样一个网格的地形: ...
- 在自己的框架中引用 PHPExcel
如果直接在框架中的controller中直接引用 xxxx/PHPExcel.php,由于框架中有autoload 与PHPExcel的autoload冲突(加载目录原因), 那么在不想做太多修改的情 ...
- 三十一、【WCF路由中间件】WCFHosting服务主机的路由器与负载均衡和实现思路
回<[开源]EFW框架系列文章索引> EFW框架源代码下载V1.3:http://pan.baidu.com/s/1c0dADO0 EFW框架实例源代码下载:http://pan.baid ...