windows環境go開環境執行個體

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

之前都是簡單測試,沒有按照go建議的開發規範來,以後要正規化。

go的開發環境規範,參見doc/code

中文連結  http://docscn.studygolang.com/doc/code.html

1.下載並安裝go

http://www.golangtc.com/download

最新的1.6.2 已經80M了。 1.1才 40M.可見go的成長還是很迅速的。

設定環境變數%GOPATH%

2。下載並安裝git用戶端

得到一個Git bash.可以在windows下用linux命令。就是很慢。

3.安裝godep

在git bash中,執行go get github.com/tools/godep 產生godep.exe在$GOPATH/bin下,複製到go的安裝運行目錄. 或者把$GOPATH/bin加到$PATH4.建立go項目(pakage)以snmp為例在$GOPATH下建立目錄/src ,/bin, /pkg在src目錄下建立psnmp, gosnmp從github下載https://github.com/soniah/gosnmp,並展開到gosnmp目錄在psnmp目錄下建立tsnmp.go

 

// Copyright 2012-2014 The GoSNMP Authors. All rights reserved.  Use of this// source code is governed by a BSD-style license that can be found in the// LICENSE file.package mainimport ("fmt""log"//g "github.com/soniah/gosnmp"g "gosnmp")func main() {// Default is a pointer to a GoSNMP struct that contains sensible defaults// eg port 161, community public, etcg.Default.Target = "192.168.6.87"err := g.Default.Connect()if err != nil {log.Fatalf("Connect() err: %v", err)}defer g.Default.Conn.Close()//oids := []string{"1.3.6.1.2.1.1.4.0", "1.3.6.1.2.1.1.7.0"}//test asciioids := []string{"1.3.6.1.2.1.2.2.1.6.0"};result, err2 := g.Default.Get(oids) // Get() accepts up to g.MAX_OIDSif err2 != nil {log.Fatalf("Get() err: %v", err2)}for i, variable := range result.Variables {fmt.Printf("%d: oid: %s ", i, variable.Name)// the Value of each variable returned by Get() implements// interface{}. You could do a type switch...switch variable.Type {case g.OctetString:fmt.Printf("string: %s\n", string(variable.Value.([]byte)))default:// ... or often you're just interested in numeric values.// ToBigInt() will return the Value as a BigInt, for plugging// into your calculations.fmt.Printf("number: %d\n", g.ToBigInt(variable.Value))}}}


5.編譯執行

可以直接運行go run src/psnmp/tsnmp.go可以直接編譯(直接在$GOPATH下產生psnmp.exe)go build psnmp可以安裝(在$GOPATH/bin下產生psnmp.exe)go install psnmp 6.使用godep儲存原始碼這個需要提交到配置庫才行,待續。

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.