go

Using multiple GOPATHs

For an example, if we set the GOPATH environment variable to /tmp/go1:/tmp/go2:/tmp/go3 all three of them will act as GOPATHs. GOPATH=/tmp/go1:/tmp/go2:/tmp/go3 But this raises a few questions. How will this affect “go get”? To test this out, simply set the GOPATH, and try go getting a simple repository. You may run these commands if you like. GOPATH=/tmp/go1:/tmp/go2:/tmp/go3 go get github.com/deis/helloworld find /tmp/ | grep helloworld | head -1 It will be clear that packages downloaded using the go get command will end up in /tmp/go1 or the first directory in the set of GOPATHs
Read more

Day 3: Packages

All go packages except packages from the standard library are placed inside the $GOPATH. A package consists of a set of go files in a directory. All go files should have “package mypackage” line before other code. There can be only one package per directory. Although it’s not required It’s expected that the directory name and the package name to be equal. By default Go provides a very large standard library.
Read more

Day 2: Built-in Features

This tutorial consists of a number of example go programs demonstrating each feature. It is recommended to try some of them on the Go playground or on your local machine. Constants are declared using the const keyword. They can be declared with a data type but it’s not common. The “Hello World” string can be stored in a constant and printed. package main func main() { const hello = "Hello World" println(hello) } Variables Variables can be declared using the var keyword.
Read more

Day 1: Getting Started

The go playground is where go code can be run easily and fast therefore it makes an efficient place to try new go code. This also makes the playground useful when learning how to program with Go. The Go playground with a very familiar go program The Go Playground is a web service that runs on golang.org’s servers. The service receives a Go program, compiles, links, and runs the program inside a sandbox, then returns the output.
Read more

Limit Go Benchmark b.N

TLDR - Operations count (b.N) can be set inside the function. Go benchmarks can be extremely useful when attempting to write performance critical applications. Both cpu and memory benchmarks can be written for Go programs. func BenchmarkHello(b *testing.B) { for i := 0; i < b.N; i++ { fmt.Sprintf("hello") } } In the above example, the fmt.Sprintf function is run b.N times in order to get a good measurement. The b.
Read more

Go for Node developers

I’m developing Node apps for years and started working with Go last month. So far, I like it as much as I like Node. So I hope to blog some quick tips about Go (aka Golang) for Node developers starting with the $GOPATH. I’ll start with some boring stuff and quickly move on to something useful. If you haven’t tried go yet, this is a good page to start. The $GOPATH It’s sort of like one path to rule them all solution.
Read more