Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Go Systems Programming

You're reading from   Go Systems Programming Master Linux and Unix system level programming with Go

Arrow left icon
Product type Paperback
Published in Sep 2017
Publisher Packt
ISBN-13 9781787125643
Length 466 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Mihalis Tsoukalos Mihalis Tsoukalos
Author Profile Icon Mihalis Tsoukalos
Mihalis Tsoukalos
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Getting Started with Go and Unix Systems Programming FREE CHAPTER 2. Writing Programs in Go 3. Advanced Go Features 4. Go Packages, Algorithms, and Data Structures 5. Files and Directories 6. File Input and Output 7. Working with System Files 8. Processes and Signals 9. Goroutines - Basic Features 10. Goroutines - Advanced Features 11. Writing Web Applications in Go 12. Network Programming

About Go

Go is a modern generic purpose open source programming language that was officially announced at the end of 2009. It began as an internal Google project and has been inspired by many other programming languages including C, Pascal, Alef, and Oberon. Its spiritual fathers are Robert Griesemer, Ken Thomson, and Rob Pike, who designed Go as a language for professional programmers who want to build reliable and robust software. Apart from its syntax and standard functions, Go comes with a pretty rich standard library.

At the time of writing this book, the latest stable Go version is 1.8, which includes some handy new features including the following: feel free to skip this if you have not used Go before:

  • New conversion rules exist that allow you to easily convert between types that are almost equal provided that some criteria are met. You can fix the import paths of the golang.org/x/net/name form to just the name of the Go source file using the go tool command without having to open the source files yourselves.
  • The operation of the tool is stricter in some cases and looser in cases that used to generate false positives.
  • There is now a default value for GOPATH Environment Variables when GOPATH is undefined. For Unix systems, the default value is $HOME/go.
  • There are various improvements to the Go runtime that speed up Go.
  • There is a sort.slice() function that allows you to sort a slice by providing a comparator callback instead of implementing sort.Interface.
  • There is now a Shutdown method to http.Server.
  • There exist various small changes to the database/sql package that give the developer more control over queries.
  • You can create bugs using the go bug command.

Getting ready for Go

You can easily find your version of Go using this command:

$ go version
go version go1.7.5 darwin/amd64  

The previous output is from a macOS machine hence the darwin string. A Linux machine would give the following kind of output:

$ go version
go version go1.3.3 linux/amd64

You will learn more about go tool, which you will use all the time, in the next chapters.

As I can imagine, you must be impatient to see some Go code; so here is the Go version of the famous Hello World program:

package main 
 
import "fmt" 
 
// This is a demonstrative comment! 
func main() { 
   fmt.Println("Hello World!") 
} 

If you are familiar with C or C++, you will find Go code pretty easy to understand. Each file that contains Go code begins with a package declaration followed by the needed import declarations. The package declaration shows the package that this file belongs to. Note that semicolons are not required for successfully terminating a Go statement unless you want to put two or more Go statements in the same line.

In Chapter 2, Writing Programs in Go, you will find out how to compile and execute Go code. For now, it is enough to remember that Go source files are stored using the .go file extension: your task is to choose a descriptive filename.

When searching for Go-related information, use Golang or golang as the keyword for the Go programming language because the word Go can be found almost everywhere in the English language and it will not help your search!
You have been reading a chapter from
Go Systems Programming
Published in: Sep 2017
Publisher: Packt
ISBN-13: 9781787125643
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime