This is a creation in Article, where the information may have evolved or changed.
Previously, it was a simple test that did not follow the development specifications recommended by go and should be formalized later.
The development environment specification for go, see Doc/code
Chinese link http://docscn.studygolang.com/doc/code.html
1. Download and install Go
Http://www.golangtc.com/download
The latest 1.6.2 is already 80M. 1.1 is 40M. It is also very fast to see the go growth.
Set environment variable%gopath%
2. Download and install the GIT client
Get a git bash. You can use Linux commands under Windows. is very slow.
3. Installing GODEP
In Git bash, execute the go get GITHUB.COM/TOOLS/GODEP build Godep.exe under $gopath/bin and copy to go's install run directory. or add $gopath/bin to $path4. Create a Go Project (pakage) to create a directory under $gopath in SNMP/src,/bin,/pkg create Psnmp in src directory, gosnmp download from GitHub https:// GITHUB.COM/SONIAH/GOSNMP, and expand to Gosnmp directory under PSNMP directory to create Tsnmp.go
Copyright 2012-2014 the Gosnmp Authors. All rights reserved. Use of this//source code was governed by a Bsd-style license the 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 SE nsible 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 () would return the Value as a BigInt, for plug ging//into your calculations.fmt.Printf ("Number:%d\n", g.tobigint (variable. Value))}}}
5. Compile execution
Can directly run go run src/psnmp/tsnmp.go can be directly compiled (directly under $gopath build Psnmp.exe) Go build PSNMP can be installed (build $gopath/bin under Psnmp.exe) go install PSNMP 6. Save the source code with GODEP this needs to be submitted to the configuration library to be continued.