Golang開發環境搭建(Windows下)

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。

一 前言

搭建go開發環境主要有以下方式:

  1. goEclipse
  2. sublime text + gosublime + gocode
  3. liteIDE

第一種,速度較慢;第三種,還得新裝一個軟體;推薦使用第二種方式。

二 步驟

  1. 安裝go環境,配置GOROOT和GOPATH,添加PATH變數
  2. 安裝package controll (crtrl + 反引號進入命令)

    輸入以下內容並斷行符號(不同版本的sublime,該內容貌似不一樣)。

    import urllib2,os; pf='Package Control.sublime-package'; ipp=sublime.installed_packages_path(); os.makedirs(ipp) if not os.path.exists(ipp) else None; urllib2.install_opener(urllib2.build_opener(urllib2.ProxyHandler())); open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('http://sublime.wbond.net/'+pf.replace(' ','%20')).read()); print 'Please restart Sublime Text to finish installation'    
  3. 安裝gosublime pakcage (ctrl + shift + p 進入包管理器)

    輸入install斷行符號,進入一個安裝pakcage的對話方塊
    輸入GoSublime 斷行符號
  4. 安裝gocode(語言自動補全精靈)(使用go get前提是已安裝git環境)

    1. go get -u github.com/nsf/gocode 擷取專案檔
    2. go install github.com/nsf/gocode 編譯專案檔得到可執行檔
    3. 配置gosublime 使用它

      Preferences ==> package settings ==> GoSublime ==> settings-Default

      將該檔案的

      "env":{},

      改為

      "env":{     "path":"E:\\GoRepo\\gocode\\bin"     },

      其中,E:\\GoRepo是筆者存放下載的go庫的總目錄,E:\GoRepo\gocode\bin`包含了gocode的可執行檔。

  5. 編寫hello檔案
  6. ctrl + b 切換到側邊欄顯示狀態

    [ E:/workspaces/golang/hello/ ] go build hello.go[ E:/workspaces/golang/hello/ ] hello

三 第一個Go項目

比如在E:\\workspaces\\golang中建立一個web項目:

$ cd /e/workspaces/golang$ mkdir myweb$ cd myweb$ mkdir src$ mkdir bin$ cd src$ mkdir server      // 弄個server包$ // 在server包下建立server.go檔案$ cd ../bin$ go build server   // 編譯server.go檔案(如果server.go引入了其它包的檔案,則編譯其它包)$ ./server            // 運行server

** 注意: ** 為了構建這個工程,必須將"E:\workspaces\golang\myweb"加入到GOPATH環境變數中。

在sublime下開發時,則可以 Preferences ==> package settings ==> GoSublime ==> settings-User,在檔案中添加如下內容:

{"env": {"GOPATH":"E:\\workspaces\\golang\\myweb"}}
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.