Introduction 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 readingI always find it interesting when I realize that something I have been practicing or dealing with for a long time has a name. This time it happens to be race conditions. This is something you can’t avoid thinking about as soon as you have more than one routine sharing any kind of resource. If you’re not thinking about race conditions in your code, now is the time.
A race condition is when two or more routines have access to the same resource, such as a variable or data structure and attempt to read and write to that resource without any regard to the other routines.
Continue readingSlices are used everywhere in my code. If I am working with data from MongoDB, it is stored in a slice. If I need to keep track of a collection of problems after running an operation, it is stored in a slice. If you don’t understand how slices work yet or have been avoiding them like I did when I started, read these two posts to learn more.
https://www.ardanlabs.com/blog/2013/08/understanding-slices-in-go-programming.html https://www.ardanlabs.com/blog/2013/08/collections-of-unknown-length-in-go.html
Continue readingAfter working in Go for some time now, I learned how to use an unbuffered channel to build a pool of goroutines. I like this implementation better than what is implemented in this post. That being said, this post still has value in what it describes.
https://github.com/goinggo/work
On more than one occasion I have been asked why I use the Work Pool pattern. Why not just start as many Go routines as needed at any given time to get the work done?
Continue readingI am working on building code to load polygons for the different Marine Forecast areas in the United States. These polygons need to be stored in MongoDB and there is a special way that needs to be done. It would not have been a big deal if it wasn’t for this fact. There isn’t just one polygon for each area. There is an external polygon and then zero to many interior polygons that need to be stored in relationship.
Continue reading