This is a guest post from Tad Vizbaras from Etasoft in South Florida. There are a number of editors and IDEs for Go development. LiteIde, Vim, Emacs and GEdit just to name a few. Each developer has their own favorite editor for each language they work with. Some like full featured IDE environments while others prefer speed over features. My personal favorite editors for Go development at the moment are Vim and GEdit.
Continue readingHave you ever found yourself in this situation. You have a case statement inside of a for loop and you would like to break from both the case and for statements in a single call?
var err error
timeout := time.After(30 * time.Second)
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, os.Interrupt)
complete := make(chan error)
go launchProcessor(complete)
for {
select {
case <-sigChan:
atomic.StoreInt32(&shutdownFlag, 1)
Continue readingLinux is unique to Windows in many ways, and writing programs in Linux is no exception. The use of standard out, standard err and null devices is not only a good idea but it’s the law. If your programs are going to be logging information, it is best to follow the destination conventions. This way your programs will work with all of the Mac/Linux tooling and hosted environments.
Go has a package in the standard library called log and a type called logger.
Continue readingI am working on a project that requires pulling and processing different XML feeds from the web and storing the data into MongoDB as JSON. Since new feeds come up everyday, changing the Go program to process and publish new feeds is out of the question. A second constraint is that processing has to work in Iron.io or any other linux cloud based environment.
What I needed was a Go program that could take an XML document and XSLT stylesheet at runtime, transform the XML into JSON and then store the JSON to MongoDB.
Continue readingIntroduction If you are using 3rd party packages, (packages that you don't own or control), you will want a way to create a reproducible build every time you build your projects. If you use 3rd party packages directly and the package authors change things, your projects could break. Even if things don't break, code changes could create inconsistent behavior and bugs.
Keith Rarick's tool godep is a great step in the right direction for managing 3rd party dependencies and creating reproducible builds.
Continue readingI was testing new functionality on a program that is already running in production when suddenly the code behaved very badly. What I saw shocked me and then it became obvious why it happened. I also have a race condition just waiting to be a problem.
I have tried to provide a simplified version of the code and the two bugs.
package main
import (
"fmt"
"os"
Continue readingIn Go values that are returned from functions are passed by value. Go gives you some nice flexibility when it comes to returning values from a function.
Here is a simple example of returning two values from a function:
package main
import (
"fmt"
)
func main() {
id, err := ReturnId()
if err != nil {
fmt.Printf("ERROR: %s", err)
return
}
Continue readingIntroduction
In my post about building and running programs in Iron.Io, I needed to switched over to my Ubuntu VM to build linux versions of my test programs locally. I love the ability to have Ubuntu available to me for building and testing my code. However, if I can stay on the Mac side it is better.
I have wanted to learn how to cross compile my Go programs for the two platforms I use, darwin/amd64 and linux/amd64.
Continue readingNathan Youngman, with the help of others, has produced this document outlining months of research and discovery. I would appreciate everyone to honestly read it before continuing with my post. http://nathany.com/go-packages/ Mitchell Hashimoto also published this post on go-nuts and everyone should read this as well. https://groups.google.com/forum/#!msg/golang-nuts/BMZDD6FM-QE/LX4JSs4NVLIJ These two documents outline the current capabilities and issues surrounding the Go tooling as it relates to package management. This has been discussed and discussed at length yet we still don't have a consensus on what the community will rally around.
Continue readingThis article was written for and published by Gopher Academy
I was looking at a code sample that showed a recursive function in Go and the writer was very quick to state how Go does not optimize for recursion, even if tail calls are explicit. I had no idea what a tail call was and I really wanted to understand what he meant by Go was not optimized for recursion. I didn't know recursion could be optimized.
Continue reading