Hands-on Go Programming
eBook - ePub

Hands-on Go Programming

Learn Google's Golang Programming, Data Structures, Error Handling and Concurrency

Sachchidanand Singh,

Share book
  1. English
  2. ePUB (mobile friendly)
  3. Available on iOS & Android
eBook - ePub

Hands-on Go Programming

Learn Google's Golang Programming, Data Structures, Error Handling and Concurrency

Sachchidanand Singh,

Book details
Book preview
Table of contents
Citations

About This Book

An easy-to-understand guide that helps you get familiar with the basics and advanced concepts in Golang

Key Features

  • Everything you need to know on how to use Go programming.
  • Illustrated Examples on Go Functions, Control Flows, and Arrays.
  • Deep Dive into Slices, Maps, Structs, Error Handling and Concurrency in Golang.

Description
Hands-on Go Programming is designed to get you up and running as fast as possible with Go. You will not just learn the basics but get introduced to how to use advanced features of Golang.The book begins with the basic concepts of Data types, Constants, Variables, Operators, Reassignment, and Redeclaration. Moving ahead, we explore and learn the use of Functions, Control flows, Arrays, Slices, Maps, and Structs using some great examples and illustrations. We then get to know about Methods in Golang. Furthermore, we learn about complex aspects of Golang such as Interfaces, Pointers, Concurrency and Error Handling.By the end, you will be familiar with both the basics and advanced concepts of Go and start developing critical programs working using this language.

What you will learn

  • Learn Golang syntaxes, control structures and Error Handling in-depth.
  • Learn to declare, create and modify Slices, Maps and Struct in Go.
  • Build your own concurrent programs with Goroutines and Channels.
  • Deep Dive into Error handling in Golang.

Who this book is for
Anyone who knows basic programming can use this book to upskill themselves in Golang. This book is also for Engineering students, IT/Software professionals, and existing Go programmers. Architects and Developers working in Cloud, Networking, and DevOps can use this book to learn Go programming and apply the knowledge gained to design and build solutions in their respective domains.

Table of Contents
1. Chapter 1 Introduction
2. Chapter 2 Functions
3. Chapter 3 Control Flows
4. Chapter 4 Arrays
5. Chapter 5 Slices
6. Chapter 6 Maps
7. Chapter 7 Structs
8. Chapter 8 Methods
9. Chapter 9 Interfaces
10. Chapter 10 Pointers
11. Chapter 11 Concurrency
12. Chapter 12 Error Handling

About the Author
Sachchidanand Singh is Advanced Analytics, BI and Data Science SME at IBM India Software Labs (ISL), Pune. He is M.Tech from Birla Institute of Technology and Science (BITS), Pilani. He has authored more than a dozen technical research papers in IEEE, international computer journals, and national/international conferences. He holds several Patents in Artificial Intelligence, Machine Learning, Cloud, and Cognitive domain. Having rich experience in architecture design and solution implementation with technologies like Advanced Analytics and Business Intelligence (BI). He is an IEEE reviewer, Technical Program Committee (TPC) member of various national/international conferences, and review board members of the American Journal of Computer Science and Information. LinkedIn Profile: www.linkedin.com/in/sachchidanand-singh-67908018 Prithvipal Singh has been working in the IT industry for nearly a decade. He has vast experience working in Java, Golang, Spring, Node.js, and Python. He has expertise in microservice architecture and the cloud domain. He is MCA from Savitribai Phule Pune University. LinkedIn Profile: www.linkedin.com/in/prithvipal-singh-2a7b4b49

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Hands-on Go Programming an online PDF/ePUB?
Yes, you can access Hands-on Go Programming by Sachchidanand Singh, in PDF and/or ePUB format, as well as other popular books in Computer Science & Open Source Programming. We have over one million books available in our catalogue for you to explore.

Information

CHAPTER 1

Introduction

The Go programming language was conceived by Robert Griesemer, Rob Pike, and Ken Thompson in 2007 at Google. It’s an open-source, general-purpose programming language that supports high-performance networking and multiprocessing. The Go compiler was initially written in C but it is now written in Go itself.

Structure

  • Data types
  • Constants, variables, and operators
  • Typed constants and untyped constants
  • Multiple constant declarations
  • Redeclaration concept
  • Reassignment concept
  • Code structure

Objective

This chapter covers the basic concepts of data types, constants, variables, operators, reassignment, and redeclaration. You will learn how to use them in the Go programming language.

Introduction

Go is a systems-level programming language for large distributed systems and highly scalable network servers. It’s well-suited for building infrastructures like networked servers and tools and is suitable for cloud, mobile applications, machine learning, etc. Go provides efficient concurrency, flexible approach to data abstraction, and supports automatic memory management, i.e., garbage collection.

Why Go programming?

Multithreading is supported by most of the programming languages, but race conditions and deadlocks create difficulties in creating the multithreaded application. For example, creating a new thread in Java consumes approximately 1 MB of the memory heap size. Now, consider a case wherein you need to spin thousands of such threads. Then, it will create out of memory.
Moreover, there is a limit to the number of cores you can add to the processors like quad-core and octa-core to increase processing power. You cannot keep on adding more cache to the processor in order to boost performance since there is a cost involved. Therefore, we are left with only one option to build a more efficient software having high performance.
Go provides a solution to the problem with goroutines. You can spin millions of them at a time since they consume ~2KB heap memory. Goroutines have faster startup time and they use more memory on a need basis only. Also, a single goroutine can run on multiple threads since goroutines and OS threads don’t have 1:1 mapping.

1.1 Data types

Data types categorize a set of related values and describe the operations that can be performed.

1.1.1 Numeric types

They are arithmetic types and represent either integer types or floating-point values.
Integer types:
uint8
Unsigned 8-bit integers (0 to 255)
uint16
Unsigned 16-bit integers (0 to 65535)
uint32
Unsigned 32-bit integers (0 to 4294967295)
uint64
Unsigned 64-bit integers (0 to 18446744073709551615)
int8
Signed 8-bit integers (-128 to 127)
int16
Signed 16-bit integers (-32768 to 32767)
int32
Signed 32-bit integers (-2147483648 to 2147483647)
int64
Signed 64-bit integers (-9223372036854775808 to 9223372036854775807)
Table 1.1
Float types:
float32
IEEE-754 32-bit floating-point numbers
float64
IEEE-754 64-bit floating-point numbers
complex64
Complex numbers with float32 real and imaginary parts
complex128
Complex numbers with float64 real and imaginary parts
Table 1.2

1.1.2 String types

Strings are immutable types. This means that once created, you can’t change the contents of a string. Go supports two styles of string literals: the double-quote style and the back-quote style.
String literals can be created using double quotes, "Go Programming" or backticks, 'Go Programming'. With regular double-quoted strings, the special...

Table of contents