Programming in Go (Golang) –setting up a MAC OS X development environment

Source: Internet
Author: User
Tags sublime text

Http://www.distilnetworks.com/setup-go-golang-ide-for-mac-os-x/#.V1Byrf50yM8

Programming in Go (Golang) –setting up a Mac OS X development environmentpublished on February 4, 2015

At Distil, we had recently started to use Go (Golang) to expand the functionality of our data platform.  A surprisingly challenging aspect of getting started with Go is setting up a development environment on my MacBook. We learned a few things along the and hopefully information below would help you setup your Go development envir Onment.

Project Workspace

The GOPATH environment variable is a key component to building Go applications.  There is several approaches to manage your project workspace and external package dependencies using the $GOPATH.  We decided to has one gopath based on the conventions in "How to Write Go Code". For example, here is my profile settings:

### Goexport GOROOT=/usr/local/Cellar/go/1.3.3/libexecexport PATH=$PATH:$GOROOTGOPATH=$HOME/distil/projects/goexport PATH=$PATH:$GOPATH/bin

We use GitHub and all Go project has a separate repository.  If The Go project requires multiple application binaries, we organize those under a separate folders.  This is inspired by Brad Fitzpatrick ' s Camlistore project. Below is a 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 has been built to help with Go dependency management. I would encourage you experiment-see-who works best for you and your organization, but we wanted to keep things  .  We Use the GPM tool which allows your to version external packages through the use of a godeps file. Each of our projects has their own godeps file and the dependencies is installed locally based on the single Gopath desc  Ribed above. The only caveat are that running ' gpm install ' for different projects with conflicting versions of the same package in the  Godeps file would 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 a IDE for Go is entirely optional and a personal preference.  All really need is a text editor and a terminal.  The trick is finding "right tool" (s) which allow you to be productive and efficient. If you is accustomed to the using tools like RubyMine, IntelliJ or Eclipse, you'll likely find it disappointing there are N  o 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 Su Blime 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 Followin G:

{  "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 SEv eral 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 was customizing the preferences to run ' go build ' and ' go test ' upon saving a go file which I slightly m Odified.  below is 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 do 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 would save you a couple of hours!

Programming in Go (Golang) –setting up a MAC OS X development environment

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.