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的更多相关文章

  1. Mac OS X下环境搭建 Sublime Text 2 环境变量配置 开发工具配置Golang (Go语言)

    Golang (Go语言) Mac OS X下环境搭建 环境变量配置 开发工具配置 Sublime Text 2 一.安装Golang的SDK 在官网http://golang.org/ 直接下载安装 ...

  2. COCOA® PROGRAMMING FOR MAC® OS X (1)- Get Start

    这个是Mac OS App开发学习的第一篇,希望是一个好的开始. 一.为什么要学习Mac OS App开发 a)长时间做IOS开发,发现自己所做的局限在苹果的一些库上面,一些底层的API却是私有的,不 ...

  3. [转]“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: * ...

  4. Mac OS 使用 Vagrant 管理虚拟机(VirtualBox)

    Vagrant(官网.github)是一款构建虚拟开发环境的工具,支持 Window,Linux,Mac OS,Vagrant 中的 Boxes 概念类似于 Docker(实质是不同的),你可以把它看 ...

  5. Mac OS、Ubuntu 安装及使用 Consul

    Consul 概念(摘录): Consul 是 HashiCorp 公司推出的开源工具,用于实现分布式系统的服务发现与配置.与其他分布式服务注册与发现的方案,比如 Airbnb 的 SmartStac ...

  6. Mac OS X 上安装 ASP.NET 5

    在Mac OS X Yosemite 10.10.3 中搭建第一个 ASP.NET 5 Web 项目 终于有时间在 Mac 上安装一下 ASP.NET 5,网上有许多教程,但是多数的时间比较早了,版本 ...

  7. 在Mac OS X Yosemite 10.10.3 中搭建第一个 ASP.NET 5 Web 项目

    终于有时间在 Mac 上安装一下 ASP.NET 5,网上有许多教程,但是多数的时间比较早了,版本不是最新,搭着 Build 2015 的春风,我也实践一下 Mac OS X 上的 ASP.NET 5 ...

  8. MAC OS VPN使用指南

    L2TP/IPSec VPN - Mac OS 使用指南 一.打开Mac的联网设置. 二.然后点左边的加号,添加新的连接. 三.选择VPN(L2TP),点击创建(Create). 四.输入你购买的VP ...

  9. Mac OS X 背后的故事

    Mac OS X 背后的故事 作者: 王越  来源: <程序员>  发布时间: 2013-01-22 10:55  阅读: 25840 次  推荐: 49   原文链接   [收藏]   ...

随机推荐

  1. 我常用的Mac快捷键

    1. 最小化当前窗口 command m 2. 在不同应用间切换 command tab 3. 在同一应用的不同窗口间切换 command ` 4. 在浏览器同一窗口的不同标签间切换 ctrl tab ...

  2. Gson 和 FastJson 性能测试

    使用版本: compile 'com.google.code.gson:gson:2.7' compile 'com.alibaba:fastjson:1.2.17' 评测样板为一个People数组, ...

  3. ASP.NET 回调技术(CallBack)

    在asp.net中客户端与服务器端的交互默认都是整页面提交, 此时客户端将当前页面表单中的数据(包括一些自动生成的隐藏域)都提交到服务器端,服务器重新实例化一个当前页面类的实例响应这个请求,然后将整个 ...

  4. adding validation annotators to model classes 在linq to EntityFrame的Model中添加前台验证validation annotators

    The same solution can be applied for LINQ to SQL. The snippet the article shows for using the Metada ...

  5. 安卓Android面试题大全

    56个问题都是经常用到的,可以深入研究下,也是必须掌握的开发必备知识. 安卓Android面试题汇总 搜集了一些Android面试题目,供将要面试或者正在面试的朋友参考. 1, 谈谈你对Activit ...

  6. Selenium WebDriver屏幕截图(C#版)

    Selenium WebDriver屏幕截图(C#版)http://www.automationqa.com/forum.php?mod=viewthread&tid=3595&fro ...

  7. Binary Tree Postorder Traversal--leetcode难题讲解系列

    https://leetcode.com/problems/binary-tree-postorder-traversal/ Given a binary tree, return the posto ...

  8. NSURLSession与AFNetworking3.0

    下面是用GET方式请求一个页面数据的示例: AFNetworking 2.x NSString *siteUrl = @"http://webinar.ofweek.com/readDemo ...

  9. WindowsServer2012桌面图标设置

    1.win+R调出运行窗口 2.输入:rundll32.exe shell32.dll,Control_RunDLL desk.cpl,,0 即可

  10. 关于python协程的一个例子的学习

    例子来自https://blog.tonyseek.com/post/event-manage-with-greenlet/ 加了一些注释看懂了: 注释中的数字表示执行的顺序,这个简单的例子用到了py ...