What is a rune?

Rune literals are just 32-bit integer values (however they’re untyped constants, so their type can change). They represent unicode codepoints. For example, the rune literal ‘a’ is actually the number 97. Therefore your program is pretty much equivalent to: It should be obvious, if you were to look at the Unicode mapping, which is identical … Read more

GO language: fatal error: all goroutines are asleep – deadlock

Go program ends when the main function ends. From the language specification Program execution begins by initializing the main package and then invoking the function main. When that function invocation returns, the program exits. It does not wait for other (non-main) goroutines to complete. Therefore, you need to wait for your goroutines to finish. The … Read more

Categories go Tags

How to uninstall Go?

72 You might try then remove any mention of go in e.g. your ~/.bashrc; then you need at least to logout and login. However, be careful when doing that. You might break your system badly if something is wrong. PS. I am assuming a Linux or POSIX system.

Categories go Tags

Is there a foreach loop in Go?

A “for” statement with a “range” clause iterates through all entries of an array, slice, string or map, or values received on a channel. For each entry it assigns iteration values to corresponding iteration variables and then executes the block. As an example: If you don’t care about the index, you can use _: The … Read more

Go build: “Cannot find package” (even though GOPATH is set)

It does not work because your foobar.go source file is not in a directory called foobar. go build and go install try to match directories, not source files. Set $GOPATH to a valid directory, e.g. export GOPATH=”$HOME/go” Move foobar.go to $GOPATH/src/foobar/foobar.go and building should work just fine. Additional recommended steps: Add $GOPATH/bin to your $PATH by: PATH=”$GOPATH/bin:$PATH” Move main.go to a subfolder of $GOPATH/src, e.g. $GOPATH/src/test go install test should now create an executable in $GOPATH/bin that can be called by … Read more

Import cycle not allowed

Here is an illustration of your first import cycle problem. As you can see with my bad ASCII chart, you are creating an import cycle when project/components/mux imports project/controllers/account. Since Go does not support circular dependencies you get the import cycle not allowed error during compile time.

Categories go

Contains method for a slice

Mostafa has already pointed out that such a method is trivial to write, and mkb gave you a hint to use the binary search from the sort package. But if you are going to do a lot of such contains checks, you might also consider using a map instead. It’s trivial to check if a specific map … Read more

Categories go Tags

How to print struct variables in console?

To print the name of the fields in a struct: From the fmt package: when printing structs, the plus flag (%+v) adds field names That supposes you have an instance of Project (in ‘yourProject‘) The article JSON and Go will give more details on how to retrieve the values from a JSON struct. This Go by example page provides another technique: … Read more

tech