博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Programming in Go (Golang) – Setting up a Mac OS X Development Environment
阅读量:7146 次
发布时间:2019-06-29

本文共 4558 字,大约阅读时间需要 15 分钟。

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

At Distil, we have recently started to use 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 .  For example, here are 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 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 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 tool 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 , or , 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 , , and , I personally settled on using and .

Sublime Text

Sublime Text 3 along with the 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 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 and 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!

转载地址:http://ergrl.baihongyu.com/

你可能感兴趣的文章
基于jQuery,使用sina ip api,实现异步ip查询
查看>>
业余的工作
查看>>
第一篇博客,希望能坚持下去
查看>>
开发者必知:提升Android应用开发性能的十大要点
查看>>
数据结构总体
查看>>
Eclipse报错:java.lang.ClassNotFoundException: ContextLoaderListener
查看>>
redis 系列23 哨兵Sentinel (上)
查看>>
软考算法题大观
查看>>
node(redis)
查看>>
Jmeter命令行运行实例讲解
查看>>
vs中正常IIS发布网站后css样式、图片丢失jQuery报错 $ is not defined
查看>>
javascript 时间函数整理
查看>>
git创建一个空的版本库
查看>>
AE模板
查看>>
Django项目vue前端依赖框架过大,工程打开太卡的问题
查看>>
VUE 入门基础(2)
查看>>
redhat7.4+shell离线安装docker
查看>>
百度地图 判断marker是否在多边形内
查看>>
数据结构之网络流入门(Network Flow)简单小节
查看>>
DB2中SQLSTATE=57016 SQLCODE=-668
查看>>