Book Image

.Go Programming Blueprints - Second Edition

By : Mat Ryer
Book Image

.Go Programming Blueprints - Second Edition

By: Mat Ryer

Overview of this book

Go is the language of the Internet age, and the latest version of Go comes with major architectural changes. Implementation of the language, runtime, and libraries has changed significantly. The compiler and runtime are now written entirely in Go. The garbage collector is now concurrent and provides dramatically lower pause times by running in parallel with other Go routines when possible. This book will show you how to leverage all the latest features and much more. This book shows you how to build powerful systems and drops you into real-world situations. You will learn to develop high quality command-line tools that utilize the powerful shell capabilities and perform well using Go's in-built concurrency mechanisms. Scale, performance, and high availability lie at the heart of our projects, and the lessons learned throughout this book will arm you with everything you need to build world-class solutions. You will get a feel for app deployment using Docker and Google App Engine. Each project could form the basis of a start-up, which means they are directly applicable to modern software markets.
Table of Contents (13 chapters)

Creating a server command

So far, all of our service code lives inside the vault package. We are now going to use this package to create a new tool to expose the server functionality.

Create a new folder in vault called cmd, and inside it create another called vaultd. We are going to put our command code inside the vaultd folder because even though the code will be in the main package, the name of the tool will be vaultd by default. If we just put the command in the cmd folder, the tool would be built into a binary called cmd-which is pretty confusing.

Note

In Go projects, if the primary use of the package is to be imported into other programs (such as Go kit), then the root level files should make up the package and will have an appropriate package name (not main). If the primary purpose is a command-line tool, such as the Drop command (https://github.com/matryer/drop), then the root files will be in the main package.

The rationale for this comes down to usability; when importing a package...