Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Learning Go Programming
Learning Go Programming

Learning Go Programming: An insightful guide to learning the Go programming language

eBook
€8.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Learning Go Programming

Chapter 1. A First Step in Go

In the first chapter of the book, you will be introduced to Go and take a tour of the features that have made the language a favorite among its adopters. The start of the chapter provides the motivation behind the Go programming language. If you are impatient, however, you are welcome to skip to any of the other topics and learn how to write your first Go program. Finally, the Go in a nutshell section provides a high-level summary of the characteristics of the language.

The following topics are covered in this chapter:

  • The Go programming language
  • Playing with Go
  • Installing Go
  • Your first Go program
  • Go in a nutshell

The Go programming language

Since the invention of the C language in the early 1970s by Dennis Ritchie at Bell Labs, the computing industry has produced many popular languages that are based directly on (or have borrowed ideas from) its syntax. Commonly known as the C-family of languages, they can be split into two broad evolutionary branches. In one branch, derivatives such as C++, C#, and Java have evolved to adopt a strong type system, object orientation, and the use of compiled binaries. These languages, however, tend to have a slow build-deploy cycle and programmers are forced to adopt a complex object-oriented type system to attain runtime safety and speed of execution:

The Go programming language

In the other evolutionary linguistic branch are languages such as Perl, Python, and JavaScript that are described as dynamic languages for their lack of type safety formalities, use of lightweight scripting syntax, and code interpretation instead of compilation. Dynamic languages have become the preferred tool for web and cloud scale development where speed and ease of deployment are valued over runtime safety. The interpreted nature of dynamic languages means, however, they generally run slower than their compiled counterparts. In addition, the lack of type safety at runtime means the correctness of the system scales poorly as the application grows.

Go was created as a system language at Google in 2007 by Robert Griesemer, Rob Pike, and Ken Thomson to handle the needs of application development. The designers of Go wanted to mitigate the issues with the aforementioned languages while creating a new language that is simple, safe, consistent, and predictable. As Rob Pike puts it:

"Go is an attempt to combine the safety and performance of a statically-typed language with the expressiveness and convenience of a dynamically-typed interpreted language."

Go borrows ideas from different languages that came before it, including:

  • Simplified but concise syntax that is fun and easy to use
  • A type of system that feels more like a dynamic language
  • Support for object-oriented programming
  • Statically typed for compilation and runtime safety
  • Compiled to native binaries for fast runtime execution
  • Near-zero compilation time that feels more like an interpreted language
  • A simple concurrency idiom to leverage multi-core, multi-chip machines
  • A garbage collector for safe and automatic memory management

The remainder of this chapter will walk you through an introductory set of steps that will give you a preview of the language and get you started with building and running your first Go program. It is a precursor to the topics that are covered in detail in the remaining chapters of the book. You are welcome to skip to other chapters if you already have a basic understanding of Go.

Playing with Go

Before we jump head-first into installing and running Go tools on your local machine, let us take a look at the Go Playground. The creators of the language have made available a simple way to familiarize yourself with the language without installing any tools. Known as the Go Playground, it is a web-based tool, accessible from https://play.golang.org/, that uses an editor metaphor to let developers test their Go skills by writing code directly within the web browser window. The Playground gives its users the ability to compile and run their code on Google's remote servers and get immediate results as shown in the following screenshot:

Playing with Go

The editor is basic, as it is meant to be used as a learning tool and a way to share code with others. The Playground includes practical features such as line numbers and formatting to ensure your code remains readable as it goes beyond a few lines long. Since this is a free service that consumes real compute resources, Google understandably imposes a few limitations on what can be done with Playground:

  • You are restricted on the amount of memory your code will consume
  • Long-running programs will be killed
  • Access to files is simulated with an in-memory filesystem.
  • Network access is simulated against the loopback interface only

No IDE required

Besides the Go Playground, how is one supposed to write Go code anyway? Writing Go does not require a fancy Integrated Development Environment (IDE). As a matter of fact, you can get started writing your simple Go programs with your favorite plain text editor that is bundled with your OS. There are, however, Go plugins for most major text editors (and full-blown IDEs) such as Atom, Vim, Emacs, Microsoft Code, IntelliJ, and many others. There is a complete list of editors and IDE plugins for Go which can be found at https://github.com/golang/go/wiki/IDEsAndTextEditorPlugins.

Installing Go

To start programming with Go on your local machine you will need to install the Go Toolchain on your computer. At the time of writing, Go comes ready to be installed on the following major OS platforms:

  • Linux
  • FreeBSD Unix
  • Mac OSX
  • Windows

The official installation packages are all available for 32-bit and 64-bit Intel-based architectures. There are also official binary releases that are available for ARM architectures as well. As Go grows in popularity, there will certainly be more binary distribution choices made available in the future.

Let us skip the detailed installation instructions as they will certainly change by the time you read this. Instead, you are invited to visit http://golang.org/doc/install and follow the directions given for your specific platform. Once completed, be sure to test your installation is working before continuing to use the following command:

$> go version
go version go1.6.1 linux/amd64

The previous command should print the version number, target OS, and the machine architecture where Go and its tools are installed. If you do not get an output similar to that preceding command, ensure to add the path of the Go binaries to your OS's execution PATH environment variable.

Before you start writing your own code, ensure that you have properly set up your GOPATH. This is a local directory where your Go source files and compiled artifacts are saved as you use the Go Toolchain. Follow the instructions found in https://golang.org/doc/install#testing to set up your GOPATH.

Source code examples

The programming examples presented throughout this book are available on the GitHub source code repository service. There you will find all source files grouped by chapters in the repository at https://github.com/vladimirvivien/learning-go/. To save the readers a few keystrokes, the examples use a shortened URL, that starts with golang.fyi, that points directly to the respective file in GitHub.

Alternatively, you can follow along by downloading and unzipping (or cloning) the repository locally. Create a directory structure in your GOPATH so that the root of the source files is located at $GOPATH/src/github.com/vladimirvivien/learning-go/.

Your first Go program

After installing the Go tools successfully on your local machine, you are now ready to write and execute your first Go program. For that, simply open your favorite text editor and type in the simple Hello World program shown in the following code:

package main
import "fmt"
func main() { 
  fmt.Println("Hello, World!")
} 

golang.fyi/ch01/helloworld.go

Save the source code in a file called helloworld.go anywhere inside your GOPATH. Then use the following Go command to compile and run the program:

$> go run helloworld.go 
Hello, World!

If all goes well, you should see the message Hello, World! output on your screen. Congratulations, you have just written and executed your first Go program. Now, let us explore the attributes and characteristics of the Go language at a high level.

Go in a nutshell

By design, Go has a simple syntax. Its designers wanted to create a language that is clear, concise, and consistent with few syntactic surprises. When reading Go code, keep this mantra in mind: what you see is what it is. Go shies away from a clever and terse coding style in favor of code that is clear and readable as exemplified by the following program:

// This program prints molecular information for known metalloids 
// including atomic number, mass, and atom count found 
// in 100 grams of each element using the mole unit. 
// See http://en.wikipedia.org/wiki/Mole_(unit) 
package main 
 
import "fmt" 
 
const avogadro float64 = 6.0221413e+23 
const grams = 100.0 
 
type amu float64 
 
func (mass amu) float() float64 { 
  return float64(mass) 
} 
 
type metalloid struct { 
  name   string 
  number int32 
  weight amu 
} 
 
var metalloids = []metalloid{ 
  metalloid{"Boron", 5, 10.81}, 
  metalloid{"Silicon", 14, 28.085}, 
  metalloid{"Germanium", 32, 74.63}, 
  metalloid{"Arsenic", 33, 74.921}, 
  metalloid{"Antimony", 51, 121.760}, 
  metalloid{"Tellerium", 52, 127.60}, 
  metalloid{"Polonium", 84, 209.0}, 
} 
 
// finds # of moles 
func moles(mass amu) float64 { 
  return float64(mass) / grams 
} 
 
// returns # of atoms moles 
func atoms(moles float64) float64 { 
  return moles * avogadro 
} 
 
// return column headers 
func headers() string { 
  return fmt.Sprintf( 
    "%-10s %-10s %-10s Atoms in %.2f Grams\n", 
    "Element", "Number", "AMU", grams, 
  ) 
} 
 
func main() { 
  fmt.Print(headers()) 
 
    for _, m := range metalloids { 
      fmt.Printf( 
    "%-10s %-10d %-10.3f %e\n", 
      m.name, m.number, m.weight.float(), atoms(moles(m.weight)), 
      ) 
    } 
}

golang.fyi/ch01/metalloids.go

When the code is executed, it will give the following output:

$> go run metalloids.go 
Element    Number     AMU        Atoms in 100.00 Grams 
Boron      5          10.810     6.509935e+22 
Silicon    14         28.085     1.691318e+23 
Germanium  32         74.630     4.494324e+23 
Arsenic    33         74.921     4.511848e+23 
Antimony   51         121.760    7.332559e+23 
Tellerium  52         127.600    7.684252e+23 
Polonium   84         209.000    1.258628e+24

If you have never seen Go before, you may not understand some of the details of the syntax and idioms used in the previous program. Nevertheless, when you read the code, there is a good chance you will be able to follow the logic and form a mental model of the program's flow. That is the beauty of Go's simplicity and the reason why so many programmers use it. If you are completely lost, no need to worry, as the subsequent chapters will cover all aspects of the language to get you going.

Functions

Go programs are composed of functions, the smallest callable code unit in the language. In Go, functions are typed entities that can either be named (as shown in the previous example) or be assigned to a variable as a value:

// a simple Go function 
func moles(mass amu) float64 { 
    return float64(mass) / grams 
} 

Another interesting feature about Go functions is their ability to return multiple values as a result of a call. For instance, the previous function could be re-written to return a value of type error in addition to the calculated float64 value:

func moles(mass amu) (float64, error) { 
    if mass < 0 { 
        return 0, error.New("invalid mass") 
    } 
    return (float64(mass) / grams), nil 
}

The previous code uses the multi-return capabilities of Go functions to return both the mass and an error value. You will encounter this idiom throughout the book used as a mean to properly signal errors to the caller of a function. There will be further discussion on multi-return value functions covered in Chapter 5, Functions in Go.

Packages

Source files containing Go functions can be further organized into directory structures known as a package. Packages are logical modules that are used to share code in Go as libraries. You can create your own local packages or use tools provided by Go to automatically pull and use remote packages from a source code repository. You will learn more about Go packages in Chapter 6, Go Packages and Programs.

The workspace

Go follows a simple code layout convention to reliably organize source code packages and to manage their dependencies. Your local Go source code is stored in the workspace, which is a directory convention that contains the source code and runtime artifacts. This makes it easy for Go tools to automatically find, build, and install compiled binaries. Additionally, Go tools rely on the workspace setup to pull source code packages from remote repositories, such as Git, Mercurial, and Subversion, and satisfy their dependencies.

Strongly typed

All values in Go are statically typed. However, the language offers a simple but expressive type system that can have the feel of a dynamic language. For instance, types can be safely inferred as shown in the following code snippet:

const grams = 100.0 

As you would expect, constant grams would be assigned a numeric type, float64, to be precise, by the Go type system. This is true not only for constants, but any variable can use a short-hand form of declaration and assignment as shown in the following example:

package main  
import "fmt"  
func main() { 
  var name = "Metalloids" 
  var triple = [3]int{5,14,84} 
  elements := []string{"Boron","Silicon", "Polonium"} 
  isMetal := false 
  fmt.Println(name, triple, elements, isMetal) 
 
} 

Notice that the variables, in the previous code snippet, are not explicitly assigned a type. Instead, the type system assigns each variable a type based on the literal value in the assignment. Chapter 2, Go Language Essentials and Chapter 4, Data Types, go into more details regarding Go types.

Composite types

Besides the types for simple values, Go also supports composite types such as array, slice, and map. These types are designed to store indexed elements of values of a specified type. For instance, the metalloid example shown previously makes use of a slice, which is a variable-sized array. The variable metalloid is declared as a slice to store a collection of the type metalloid. The code uses the literal syntax to combine the declaration and assignment of a slice of type metalloid:

var metalloids = []metalloid{ 
    metalloid{"Boron", 5, 10.81}, 
    metalloid{"Silicon", 14, 28.085}, 
    metalloid{"Germanium", 32, 74.63}, 
    metalloid{"Arsenic", 33, 74.921}, 
    metalloid{"Antimony", 51, 121.760}, 
    metalloid{"Tellerium", 52, 127.60}, 
    metalloid{"Polonium", 84, 209.0}, 
} 

Go also supports a struct type which is a composite that stores named elements called fields as shown in the following code:

func main() { 
  planet := struct { 
      name string 
      diameter int  
  }{"earth", 12742} 
} 

The previous example uses the literal syntax to declare struct{name string; diameter int} with the value {"earth", 12742}. You can read all about composite types in Chapter 7, Composite Types.

The named type

As discussed, Go provides a healthy set of built-in types, both simple and composite. Go programmers can also define new named types based on an existing underlying type as shown in the following snippet extracted from metalloid in the earlier example:

type amu float64 
 
type metalloid struct { 
  name string 
  number int32 
  weight amu 
} 

The previous snippet shows the definition of two named types, one called amu, which uses type float64 as its underlying type. Type metalloid, on the other hand, uses a struct composite type as its underlying type, allowing it to store values in an indexed data structure. You can read more about declaring new named types in Chapter 4, Data Types.

Methods and objects

Go is not an object-oriented language in a classical sense. Go types do not use a class hierarchy to model the world as is the case with other object-oriented languages. However, Go can support the object-based development idiom, allowing data to receive behaviors. This is done by attaching functions, known as methods, to named types.

The following snippet, extracted from the metalloid example, shows the type amu receiving a method called float() that returns the mass as a float64 value:

type amu float64 
 
func (mass amu) float() float64 { 
    return float64(mass) 
} 

The power of this concept is explored in detail in Chapter 8, Methods, Interfaces, and Objects.

Interfaces

Go supports the notion of a programmatic interface. However, as you will see in Chapter 8, Methods, Interfaces, and Objects, the Go interface is itself a type that aggregates a set of methods that can project capabilities onto values of other types. Staying true to its simplistic nature, implementing a Go interface does not require a keyword to explicitly declare an interface. Instead, the type system implicitly resolves implemented interfaces using the methods attached to a type.

For instance, Go includes the built-in interface called Stringer, defined as follows:

type Stringer interface { 
    String() string 
} 

Any type that has the method String() attached, automatically implements the Stringer interface. So, modifying the definition of the type metalloid, from the previous program, to attach the method String() will automatically implement the Stringer interface:

type metalloid struct { 
    name string 
    number int32 
    weight amu 
} 
func (m metalloid) String() string { 
  return fmt.Sprintf( 
    "%-10s %-10d %-10.3f %e", 
    m.name, m.number, m.weight.float(), atoms(moles(m.weight)), 
  ) 
}  

golang.fyi/ch01/metalloids2.go

The String() methods return a pre-formatted string that represents the value of a metalloid. The function Print(), from the standard library package fmt, will automatically call the method String(), if its parameter implements stringer. So, we can use this fact to print metalloid values as follow:

func main() { 
  fmt.Print(headers()) 
  for _, m := range metalloids { 
    fmt.Print(m, "\n") 
  } 
} 

Again, refer to Chapter 8, Methods, Interfaces, and Objects, for a thorough treatment of the topic of interfaces.

Concurrency and channels

One of the main features that has rocketed Go to its current level of adoption is its inherent support for simple concurrency idioms. The language uses a unit of concurrency known as a goroutine, which lets programmers structure programs with independent and highly concurrent code.

As you will see in the following example, Go also relies on a construct known as a channel used for both communication and coordination among independently running goroutines. This approach avoids the perilous and (sometimes brittle) traditional approach of thread communicating by sharing memory. Instead, Go facilitates the approach of sharing by communicating using channels. This is illustrated in the following example that uses both goroutines and channels as processing and communication primitives:

// Calculates sum of all multiple of 3 and 5 less than MAX value. 
// See https://projecteuler.net/problem=1 
package main 
 
import ( 
  "fmt" 
) 
 
const MAX = 1000 
 
func main() { 
  work := make(chan int, MAX) 
  result := make(chan int) 
 
  // 1. Create channel of multiples of 3 and 5 
  // concurrently using goroutine 
  go func(){ 
    for i := 1; i < MAX; i++ { 
      if (i % 3) == 0 || (i % 5) == 0 { 
        work <- i // push for work 
      } 
    } 
    close(work)  
  }() 
 
  // 2. Concurrently sum up work and put result 
  //    in channel result  
  go func(){ 
    r := 0 
    for i := range work { 
      r = r + i 
    } 
    result <- r 
  }() 
 
  // 3. Wait for result, then print 
  fmt.Println("Total:", <- result) 
} 

golang.fyi/ch01/euler1.go

The code in the previous example splits the work to be done between two concurrently running goroutines (declared with the go keyword) as annotated in the code comment. Each goroutine runs independently and uses the Go channels, work and result, to communicate and coordinate the calculation of the final result. Again, if this code does not make sense at all, rest assured, concurrency has the whole of Chapter 9, Concurrency, dedicated to it.

Memory management and safety

Similar to other compiled and statically-typed languages such as C and C++, Go lets developers have direct influence on memory allocation and layout. When a developer creates a slice (think array) of bytes, for instance, there is a direct representation of those bytes in the underlying physical memory of the machine. Furthermore, Go borrows the notion of pointers to represent the memory addresses of stored values giving Go programs the support of passing function parameters by both value and reference.

Go asserts a highly opinionated safety barrier around memory management with little to no configurable parameters. Go automatically handles the drudgery of bookkeeping for memory allocation and release using a runtime garbage collector. Pointer arithmetic is not permitted at runtime; therefore, developers cannot traverse memory blocks by adding to or subtracting from a base memory address.

Fast compilation

Another one of Go's attractions is its millisecond build-time for moderately-sized projects. This is made possible with features such as a simple syntax, conflict-free grammar, and a strict identifier resolution that forbids unused declared resources such as imported packages or variables. Furthermore, the build system resolves packages using transitivity information stored in the closest source node in the dependency tree. Again, this reduces the code-compile-run cycle to feel more like a dynamic language instead of a compiled language.

Testing and code coverage

While other languages usually rely on third-party tools for testing, Go includes both a built-in API and tools designed specifically for automated testing, benchmarking, and code coverage. Similar to other features in Go, the test tools use simple conventions to automatically inspect and instrument the test functions found in your code.

The following function is a simplistic implementation of the Euclidean division algorithm that returns a quotient and a remainder value (as variables q and r) for positive integers:

func DivMod(dvdn, dvsr int) (q, r int) { 
  r = dvdn 
  for r >= dvsr { 
    q += 1 
    r = r - dvsr 
  } 
  return 
} 

golang.fyi/ch01/testexample/divide.go

In a separate source file, we can write a test function to validate the algorithm by checking the remainder value returned by the tested function using the Go test API as shown in the following code:

package testexample 
import "testing" 
func TestDivide(t *testing.T) { 
  dvnd := 40 
    for dvsor := 1; dvsor < dvnd; dvsor++ { 
      q, r := DivMod(dvnd, dvsor) 
  if (dvnd % dvsor) != r { 
    t.Fatalf("%d/%d q=%d, r=%d, bad remainder.", dvnd, dvsor, q, r) 
    } 
  } 
}  

golang.fyi/ch01/testexample/divide_test.go

To exercise the test source code, simply run Go's test tool as shown in the following example:

$> go test . 
ok   github.com/vladimirvivien/learning-go/ch01/testexample  0.003s

The test tool reports a summary of the test result indicating the package that was tested and its pass/fail outcome. The Go Toolchain comes with many more features designed to help programmers create testable code, including:

  • Automatically instrument code to gather coverage statistics during tests
  • Generating HTML reports for covered code and tested paths
  • A benchmark API that lets developers collect performance metrics from tests
  • Benchmark reports with valuable metrics for detecting performance issues

You can read all about testing and its related tools in Chapter 12, Code Testing.

Documentation

Documentation is a first-class component in Go. Arguably, the language's popularity is in part due to its extensive documentation (see http://golang.org/pkg). Go comes with the Godoc tool, which makes it easy to extract documentation from comment text embedded directly in the source code. For example, to document the function from the previous section, we simply add comment lines directly above the DivMod function as shown in the following example:

// DivMod performs a Eucledan division producing a quotient and remainder. 
// This version only works if dividend and divisor > 0. 
func DivMod(dvdn, dvsr int) (q, r int) { 
... 
}

The Go documentation tool can automatically extract and create HTML-formatted pages. For instance, the following command will start the Godoc tool as a server on localhost port 6000:

$> godoc -http=":6001"

You can then access the documentation of your code directly from your web browser. For instance, the following figure shows the generated documentation snippet for the previous function located at http://localhost:6001/pkg/github.com/vladimirvivien/learning-go/ch01/testexample/:

Documentation

An extensive library

For its short existence, Go rapidly grew a collection of high-quality APIs as part of its standard library that are comparable to other popular and more established languages. The following, by no means exhaustive, lists some of the core APIs that programmers get out-of-the-box:

  • Complete support for regular expressions with search and replace
  • Powerful IO primitives for reading and writing bytes
  • Full support for networking from socket, TCP/UDP, IPv4, and IPv6
  • APIs for writing production-ready HTTP services and clients
  • Support for traditional synchronization primitives (mutex, atomic, and so on)
  • General-purpose template framework with HTML support
  • Support for JSON/XML serializations
  • RPC with multiple wire formats
  • APIs for archive and compression algorithms: tar, zip/gzip, zlib, and so on
  • Cryptography support for most major algorithms and hash functions
  • Access to OS-level processes, environment info, signaling, and much more

The Go Toolchain

Before we end the chapter, one last aspect of Go that should be highlighted is its collection of tools. While some of these tools were already mentioned in previous sections, others are listed here for your awareness:

  • fmt: Reformats source code to adhere to the standard
  • vet: Reports improper usage of source code constructs
  • lint: Another source code tool that reports flagrant style infractions
  • goimports: Analyzes and fixes package import references in source code
  • godoc: Generates and organizes source code documentation
  • generate: Generates Go source code from directives stored in source code
  • get: Remotely retrieves and installs packages and their dependencies
  • build: Compiles code in a specified package and its dependencies
  • run: Provides the convenience of compiling and running your Go program
  • test: Performs unit tests with support for benchmark and coverage reports
  • oracle static analysis tool: Queries source code structures and elements
  • cgo: Generates source code for interoperability between Go and C

Summary

Within its relatively short existence, Go has won the hearts of many adopters who value simplicity as a way to write code that is exact and is able to scale in longevity. As you have seen from the previous sections in this chapter, it is easy to get started with your first Go program.

The chapter also exposed its readers to a high-level summary of the most essential features of Go including its simplified syntax, its emphasis on concurrency, and the tools that make Go a top choice for software engineers, creating systems for the age of data center computing. As you may imagine, this is just a taste of what's to come.

In the following chapters, the book will continue to explore in detail the syntactical elements and language concepts that make Go a great language to learn. Let's Go!

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Insightful coverage of Go programming syntax, constructs, and idioms to help you understand Go code effectively
  • Push your Go skills, with topics such as, data types, channels, concurrency, object-oriented Go, testing, and network programming
  • Each chapter provides working code samples that are designed to help reader quickly understand respective topic

Description

The Go programming language has firmly established itself as a favorite for building complex and scalable system applications. Go offers a direct and practical approach to programming that let programmers write correct and predictable code using concurrency idioms and a full-featured standard library. This is a step-by-step, practical guide full of real world examples to help you get started with Go in no time at all. We start off by understanding the fundamentals of Go, followed by a detailed description of the Go data types, program structures and Maps. After this, you learn how to use Go concurrency idioms to avoid pitfalls and create programs that are exact in expected behavior. Next, you will be familiarized with the tools and libraries that are available in Go for writing and exercising tests, benchmarking, and code coverage. Finally, you will be able to utilize some of the most important features of GO such as, Network Programming and OS integration to build efficient applications. All the concepts are explained in a crisp and concise manner and by the end of this book; you would be able to create highly efficient programs that you can deploy over cloud.

Who is this book for?

If you have prior exposure to programming and are interested in learning the Go programming language, this book is designed for you. It will quickly run you through the basics of programming to let you exploit a number of features offered by Go programming language.

What you will learn

  • Install and configure the Go development environment to quickly get started with your first program.
  • Use the basic elements of the language including source code structure, variables, constants, and control flow primitives to quickly get started with Go
  • Gain practical insight into the use of Go s type system including basic and composite types such as maps, slices, and structs.
  • Use interface types and techniques such as embedding to create idiomatic object-oriented programs in Go.
  • Develop effective functions that are encapsulated in well-organized package structures with support for error handling and panic recovery.
  • Implement goroutine, channels, and other concurrency primitives to write highly-concurrent and safe Go code
  • Write tested and benchmarked code using Go's built test tools
  • Access OS resources by calling C libraries and interact with program environment at runtime

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Oct 26, 2016
Length: 348 pages
Edition : 1st
Language : English
ISBN-13 : 9781784392338
Vendor :
Google
Category :
Languages :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Oct 26, 2016
Length: 348 pages
Edition : 1st
Language : English
ISBN-13 : 9781784392338
Vendor :
Google
Category :
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 125.97
Learning Go Programming
€41.99
.Go Programming Blueprints
€41.99
Go Design Patterns
€41.99
Total 125.97 Stars icon
Banner background image

Table of Contents

12 Chapters
1. A First Step in Go Chevron down icon Chevron up icon
2. Go Language Essentials Chevron down icon Chevron up icon
3. Go Control Flow Chevron down icon Chevron up icon
4. Data Types Chevron down icon Chevron up icon
5. Functions in Go Chevron down icon Chevron up icon
6. Go Packages and Programs Chevron down icon Chevron up icon
7. Composite Types Chevron down icon Chevron up icon
8. Methods, Interfaces, and Objects Chevron down icon Chevron up icon
9. Concurrency Chevron down icon Chevron up icon
10. Data IO in Go Chevron down icon Chevron up icon
11. Writing Networked Services Chevron down icon Chevron up icon
12. Code Testing Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.8
(5 Ratings)
5 star 80%
4 star 20%
3 star 0%
2 star 0%
1 star 0%
Shines Dec 03, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Vladimir Vivien's Learn Go Programming is a timely and practical hands-on guide to accelerate your learning curve with Google's fast growing program. Go is know for its ability to handle large, complex software in a team environment. Vladimir provides sample code, tips and warnings to help programmers at all levels avoid pitfalls. As a former IBM principal & E&Y consultant working with multinational corporations, I appreciate the value of what Vivien's Learn Go Programming can bring to individuals and large enterprise teams. Finally, as Director of Analytics and Continuous Improvement I see how Go plays a vital role for writing the code to manage complex server networks, needed to handle #big data, #machine learning and #IoT. I give Mr Vivien's Learn Go my highest recommendation
Amazon Verified review Amazon
Yemi Yisa Sep 25, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Buy the book. I LOVE his writing style. Straight to the point, not confusing, and extremely easy to digest.
Amazon Verified review Amazon
IOA M DOUNIS Nov 03, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I own dozens of programming language books and i have been programming for 24 years. This is one of the best introductory books i own on learning a new programming language, and the best, hands down, on the GO programming Language.If you want to learn programming in this powerful and wonderful language and you are already familiar with programming you must read this book first, the author is honest with his words, he wishes he had such a book when he begun learning GO, i wish the same!
Amazon Verified review Amazon
Manish kumar Jul 01, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
really nice for begginers and in details
Amazon Verified review Amazon
Jason S Chvat Apr 12, 2022
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Good book overall. Straight forward, easy examples. My one issue is that it is literally riddled with typos and small code errors. I could tell based on previous programming experience where they were but if I didn't have the experience it could be very confusing
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.