Book Image

Go Design Patterns

By : Mario Castro Contreras
Book Image

Go Design Patterns

By: Mario Castro Contreras

Overview of this book

Go is a multi-paradigm programming language that has built-in facilities to create concurrent applications. Design patterns allow developers to efficiently address common problems faced during developing applications. Go Design Patterns will provide readers with a reference point to software design patterns and CSP concurrency design patterns to help them build applications in a more idiomatic, robust, and convenient way in Go. The book starts with a brief introduction to Go programming essentials and quickly moves on to explain the idea behind the creation of design patterns and how they appeared in the 90’s as a common "language" between developers to solve common tasks in object-oriented programming languages. You will then learn how to apply the 23 Gang of Four (GoF) design patterns in Go and also learn about CSP concurrency patterns, the "killer feature" in Go that has helped Google develop software to maintain thousands of servers. With all of this the book will enable you to understand and apply design patterns in an idiomatic way that will produce concise, readable, and maintainable software.
Table of Contents (17 chapters)
Go Design Patterns
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

The Go get tool


Go get is a tool to get third party projects from CVS repositories. Instead of using the git clone command, you can use Go get to receive a series of added benefits. Let's write an example using CoreOS's ETCD project which is a famous distributed key-value store.

CoreOS's ETCD is hosted on GitHub at  https://github.com/coreos/etcd.git. To download this project source code using the Go get tool, we must type in the Terminal it's resulting import path that it will have in our GOPATH:

$ go get github.com/coreos/etcd

Note that we have just typed the most relevant information so that Go get figures out the rest. You'll get some output, depending on the state of the project, but after, while, it will disappear. But what did happen?

  • Go get has created a folder in $GOPATH/src/github.com/coreos.

  • It has cloned the project in that location, so now the source code of ETCD is available at $GOPATH/src/github.com/coreos/etcd.

  • Go get has cloned any repository that ETCD could need.

  • It has tried to install the project if it is not a library. This means, it has generated a binary file of ETCD and has put it in $GOPATH/bin folder.

By simply typing the go get [project] command, you'll get all that material from a project in your system. Then in your Go apps, you can just use any library by importing the path within the source. So for the ETCD project, it will be:

import "github.com/coreos/etcd" 

It's very important that you get familiar with the use of the Go get tool and stop using git clone when you want a project from a Git repository. This will save you some headaches when trying to import a project that isn't contained within your GOPATH.