Programming in Go (Golang) – Setting up a Mac OS X Development Environment

来源:http://www.cnblogs.com/kungfupanda/archive/2016/06/03/5554962.html
-Advertisement-
Play Games

http://www.distilnetworks.com/setup-go-golang-ide-for-mac-os-x/#.V1Byrf50yM8 Programming in Go (Golang) – Setting up a Mac OS X Development Environmen ...


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

Golang GopherAt 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 gpm 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 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!


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 動機 今天有朋友寫信說他認為自己的wordpress博客內顯示的訪問統計信息不正常,希望我能為他製造一些訪問信息,供他對比。朋友提出的請求是在短時間內快速打開100個不同的博客頁面,以便他從產生的訪問量變化中理解博客訪問數據。 本人作為一個搞電腦的人,有把任何重覆性勞動自動化的衝動,所以雖然點開1 ...
  • 本文示例代碼測試環境是Windows下的APMServ(PHP5.2.6) 簡述 可能大家都知道,php中有一個函數叫debug_backtrace,它可以回溯跟蹤函數的調用信息,可以說是一個調試利器。 好,來複習一下。 one(); function one() { two(); } functi ...
  • C++這門語言從誕生到今天已經經歷了將近30個年頭。不可否認,它的學習難度都比其它語言較高。而它的學習難度,主要來自於它的複雜性。現在C++的使用範圍比以前已經少了很多,java、C#、python等語言在很多方面已經可以代替C++。但是也有很多地方是其他語言完全無法替代的,主要集中在需要運行效率比 ...
  • Ok,我又來寫SOLR的內容了,昨天做了修改和增加的增量索引,今天來說說關於刪除的增量索引以及定時更新增量索引,廢話不多說,下麵進入正文。 一、增量索引之刪除 昨天已經說過,增量索引其實就是SOLR對上次做過(增量或者全量)索引之後到這次做索引之間的這段時間資料庫發生變化的數據進行創建索引,昨天我們 ...
  • 1. D:\AWS_workspace\DAAS_Go>go get -u -ldflags -H=windowsgui github.com/nsf/gocode 2. Then gocode.exe will be installed in "D:\AWS_workspace\DAAS_Go\b ...
  • http://blog.csdn.net/hengyunabc/article/details/7371446 本文章地址:http://blog.csdn.net/hengyunabc/article/details/7371446 2012-03-31:新版的goclipse改進很大,本文有些內 ...
  • 最近想學習下Go語言,先從最基本的Hello Go開始,搭建Go開發環境 一、下載Go包 由於Go官網國內訪問經常有問題,可以從國內的鏡像下載: http://www.golangtc.com/ 二、配置環境變數 1、將Go的壓縮包解壓到任意目錄,我的為D:\SDE\go 2、 配置GoRoot路徑 ...
  • http://www.cnblogs.com/qgymje/p/3912259.html 這篇原來是給公司里使用go開發的交流用的,主要是工具的安裝,用markdown寫的,發佈了內部gitlab上,倉促發佈到blog上面,也沒改啥格式,現在整理一下,然後增加一點說明 基礎開發工具 sublime ...
一周排行
    -Advertisement-
    Play Games
  • 示例項目結構 在 Visual Studio 中創建一個 WinForms 應用程式後,項目結構如下所示: MyWinFormsApp/ │ ├───Properties/ │ └───Settings.settings │ ├───bin/ │ ├───Debug/ │ └───Release/ ...
  • [STAThread] 特性用於需要與 COM 組件交互的應用程式,尤其是依賴單線程模型(如 Windows Forms 應用程式)的組件。在 STA 模式下,線程擁有自己的消息迴圈,這對於處理用戶界面和某些 COM 組件是必要的。 [STAThread] static void Main(stri ...
  • 在WinForm中使用全局異常捕獲處理 在WinForm應用程式中,全局異常捕獲是確保程式穩定性的關鍵。通過在Program類的Main方法中設置全局異常處理,可以有效地捕獲並處理未預見的異常,從而避免程式崩潰。 註冊全局異常事件 [STAThread] static void Main() { / ...
  • 前言 給大家推薦一款開源的 Winform 控制項庫,可以幫助我們開發更加美觀、漂亮的 WinForm 界面。 項目介紹 SunnyUI.NET 是一個基於 .NET Framework 4.0+、.NET 6、.NET 7 和 .NET 8 的 WinForm 開源控制項庫,同時也提供了工具類庫、擴展 ...
  • 說明 該文章是屬於OverallAuth2.0系列文章,每周更新一篇該系列文章(從0到1完成系統開發)。 該系統文章,我會儘量說的非常詳細,做到不管新手、老手都能看懂。 說明:OverallAuth2.0 是一個簡單、易懂、功能強大的許可權+可視化流程管理系統。 有興趣的朋友,請關註我吧(*^▽^*) ...
  • 一、下載安裝 1.下載git 必須先下載並安裝git,再TortoiseGit下載安裝 git安裝參考教程:https://blog.csdn.net/mukes/article/details/115693833 2.TortoiseGit下載與安裝 TortoiseGit,Git客戶端,32/6 ...
  • 前言 在項目開發過程中,理解數據結構和演算法如同掌握蓋房子的秘訣。演算法不僅能幫助我們編寫高效、優質的代碼,還能解決項目中遇到的各種難題。 給大家推薦一個支持C#的開源免費、新手友好的數據結構與演算法入門教程:Hello演算法。 項目介紹 《Hello Algo》是一本開源免費、新手友好的數據結構與演算法入門 ...
  • 1.生成單個Proto.bat內容 @rem Copyright 2016, Google Inc. @rem All rights reserved. @rem @rem Redistribution and use in source and binary forms, with or with ...
  • 一:背景 1. 講故事 前段時間有位朋友找到我,說他的窗體程式在客戶這邊出現了卡死,讓我幫忙看下怎麼回事?dump也生成了,既然有dump了那就上 windbg 分析吧。 二:WinDbg 分析 1. 為什麼會卡死 窗體程式的卡死,入口門檻很低,後續往下分析就不一定了,不管怎麼說先用 !clrsta ...
  • 前言 人工智慧時代,人臉識別技術已成為安全驗證、身份識別和用戶交互的關鍵工具。 給大家推薦一款.NET 開源提供了強大的人臉識別 API,工具不僅易於集成,還具備高效處理能力。 本文將介紹一款如何利用這些API,為我們的項目添加智能識別的亮點。 項目介紹 GitHub 上擁有 1.2k 星標的 C# ...