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 原文链接 [收藏] ...
随机推荐
- wpf xaml inlines
string testBold = "<Bold>Sync Now</Bold>"; var ele = System.Windows. ...
- Spring3系列6 - Spring 表达式语言(Spring EL)
Spring3系列6-Spring 表达式语言(Spring EL) 本篇讲述了Spring Expression Language —— 即Spring3中功能丰富强大的表达式语言,简称SpEL.S ...
- MD5 加密的两种方法
System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5Cryp ...
- [转]Android dex分包方案
转载自:https://m.oschina.net/blog/308583 当一个app的功能越来越复杂,代码量越来越多,也许有一天便会突然遇到下列现象: 1. 生成的apk在2.3以前的机器无法安装 ...
- tcp为什要三次握手
准备知识: 单工:信息只能单向传递.发送-->接收,单向,不能返回响应. 双工:指的是信息可双向发送. 全双工:信息可同时双向传递. 半双工:不能同时,单行道,一边传输完了,另一边才能发起传输. ...
- Git 分支合并
理解核心 Git最初只有一个分支,所有后续分支都是直接或间接的从这个分支切出来的. 在任意两个分支上,向前追溯提交记录,都能找到一个最近的提交同时属于这两个分支,这个提交就是两个分支的分叉节点 分支合 ...
- Tips10:你可以像写文档一样自由的复制粘贴游戏组件(Game Object Component)
相对于添加组件后再进行调整和赋值,通过复制和粘贴已有游戏组件能够带来更高的效率.
- 【转载】一步一步写算法(之hash表)
转载自:http://blog.csdn.net/feixiaoxing/article/details/6885657 [ 声明:版权所有,欢迎转载,请勿用于商业用途. 联系信箱:feixiaox ...
- Laravel 5 服务的注册和使用
首先我们需要创建一个服务的类,比如叫CqhServiceProvider,最简单的方式就是用artisan来帮我们创建 php artisan make:provider CqhServiceProv ...
- 终极事务处理(XTP,Hekaton)——万能大招?
在SQL Server 2014里,微软引入了终极事务处理(Extreme Transaction Processing),即大家熟知的Hekaton.我在网上围观了一些文档,写这篇文章,希望可以让大 ...