Posts

Showing posts with the label Go

Can I Import 3rd Party Package Into Golang Playground

Answer : Since May 14th, 2019, it is now possible (from Brad Fitzpatrick)! The #golang playground now supports third-party imports, pulling them in via https://proxy.golang.org/ Example: https://play.golang.org/p/eqEo7mqdS9l Multi-file support & few other things up next. Report bugs at golang/go issue 31944, or here on the tweeters. (On the "multiple file" support , see, since May. 16th 2019, "Which packages may be imported in the go playground?": see an example here) netbrain suggests in the comments another example: On the playground: package main import ( "fmt" "gonum.org/v1/gonum/mat" ) func main() { v1 := mat.NewVecDense(4,[]float64{1,2,3,4}) fmt.Println(mat.Dot(v1,v1)) } woud give '30', using mat.NewVecDense() to create a column vector, and mat.Dot() to return the sum of the element-wise product of v1 and v1 The point being: gonum/mat is not part of the Go Standard Library. Original ans...

Cannot Download, $GOPATH Not Set

Answer : [Update: as of Go 1.8, GOPATH defaults to $HOME/go , but you may still find this useful if you want to understand the GOPATH layout, customize it, etc.] The official Go site discusses GOPATH and how to lay out a workspace directory. export GOPATH="$HOME/your-workspace-dir/" -- run it in your shell, then add it to ~/.bashrc or equivalent so it will be set for you in the future. Go will install packages under src/ , bin/ , and pkg/ , subdirectories there. You'll want to put your own packages somewhere under $GOPATH/src , like $GOPATH/src/github.com/myusername/ if you want to publish to GitHub. You'll also probably want export PATH=$PATH:$GOPATH/bin in your .bashrc so you can run compiled programs under $GOPATH . Optionally, via Rob Pike, you can also set CDPATH so it's faster to cd to package dirs in bash: export CDPATH=.:$GOPATH/src/github.com:$GOPATH/src/golang.org/x means you can just type cd net/html instead of cd $GOPATH/src/golang....