Statistics
26
Views
0
Downloads
0
Donations
Support
Share
Uploader

高宏飞

Shared on 2026-01-29

AuthorSachchidanand Singh, Prithvipal Singh

An easy-to-understand guide that helps you get familiar with the basics and advanced concepts in GolangKey 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. Furthe

Tags
No tags
ISBN: 9389898196
Publisher: BPB Publications
Publish Year: 2021
Language: 英文
Pages: 240
File Format: PDF
File Size: 2.4 MB
Support Statistics
¥.00 · 0times
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

(This page has no text content)
Hands-on Go Programming Learn Google’s Golang Programming, Data Structures, Error Handling and Concurrency Sachchidanand Singh Prithvipal Singh www.bpbonline.com
FIRST EDITION 2021 Copyright © BPB Publications, India ISBN: 978-93-89898-19-4 All Rights Reserved. No part of this publication may be reproduced, distributed or transmitted in any form or by any means or stored in a database or retrieval system, without the prior written permission of the publisher with the exception to the program listings which may be entered, stored and executed in a computer system, but they can not be reproduced by the means of publication, photocopy, recording, or by any electronic and mechanical means. LIMITS OF LIABILITY AND DISCLAIMER OF WARRANTY The information contained in this book is true to correct and the best of author’s and publisher’s knowledge. The author has made every effort to ensure the accuracy of these publications, but publisher cannot be held responsible for any loss or damage arising from any information in this book. All trademarks referred to in the book are acknowledged as properties of their respective owners but BPB Publications cannot guarantee the accuracy of this information. Distributors:
BPB PUBLICATIONS 20, Ansari Road, Darya Ganj New Delhi-110002 Ph: 23254990/23254991 MICRO MEDIA Shop No. 5, Mahendra Chambers, 150 DN Rd. Next to Capital Cinema, V.T. (C.S.T.) Station, MUMBAI-400 001 Ph: 22078296/22078297 DECCAN AGENCIES 4-3-329, Bank Street, Hyderabad-500195 Ph: 24756967/24756400
BPB BOOK CENTRE 376 Old Lajpat Rai Market, Delhi-110006 Ph: 23861747 Published by Manish Jain for BPB Publications, 20 Ansari Road, Darya Ganj, New Delhi-110002 and Printed by him at Repro India Ltd, Mumbai www.bpbonline.com
Dedicated to My Parents, Wife Nirmala & Loving Daughter Anvi and Son Vansh — Sachchidanand Singh My Parents, Wife Rajani & Loving son Parthiv — Prithvipal Singh
About the Authors Mr. Sachchidanand Singh is working as Advanced Analytics, BI and Data Science SME at IBM India Software Labs (ISL), Pune. He is M.Tech from the 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. He has 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 a review board member of the American Journal of Computer Science and Information Engineering, USA. Mr. 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 has an MCA from Savitribai Phule Pune University.
About the Reviewer Dolly Talreja is currently working as the technical lead and core member of a team developing 5G Core network (Golang Linux) and is an integral part of Altran Technologies. In her capacity, she is the owner of the nodes UDM and AUSF and is involved in completing SDLC. She is also an expert in analyzing network traces. She is part of a team that is at the forefront of innovation to address the entire breadth of the clients’ opportunities in the evolving world of cloud and digital platforms. She is the alumni of NIT Warangal, with more than 6 years of experience in the industry, was the Lead Engineer at HP and played a key role in the development of LEDM. She is the owner of the Scan to Feature of HP. She was also part of the Samsung R&D Institute of India as the Senior Software Engineer and was part of a team developing SMB 3.0 protocol for Samsung’s MPF. She also has to her credit a published paper in IEEE on decentralized peer-to-peer networks.
Acknowledgements At this movement of my substantial enhancement, before we get into the thick of the things, we would like to add a few heartfelt words for the people who gave their unending support with their unfair humor and warm wishes. First and foremost, praises and thanks to the God, the Almighty, for his showers of blessings throughout in completing this book successfully. We want to acknowledge our colleagues who provided us with the impetus to write a more suitable text. We are thankful to the management, seniors and colleagues for constantly keeping on pushing us to move higher and higher. Besides them, we thank all our friends, well-wishers, respondents, and academicians who helped us throughout our journey from the inception to the completion.
Preface Golang is regarded as a swift and flawless programming language having loads of useful features like efficient built-in concurrency, garbage collector with automatic garbage detection and cleaning, dynamic growable call stack of goroutines, extremely fast compiler and cross platform versatility, etc. A lot of cloud, networking, and DevOps softwares are written in Golang like Docker, Kubernetes, Terraform, etcd, and ist.io. The Go developers community is one of the most active open source communities on GitHub. This book focuses on learning Golang, starting from the basic concepts to interfaces, pointers, concurrency, etc. We have explained each concept in detail using programming examples. We start with the basics and get into more complex stuff with each chapter. Each chapter has exercises which will help you in understanding the concepts clearly. Over the 12 chapters in this book, you will learn the following: Chapter 1: [Introduction] 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. Chapter 2: [Functions]
This chapter will cover the function declaration, parameters, multiple returns, variadic function, and defer statement. It will also cover the concept of call by value and how to pass the address of the variable as a value. Chapter 3: [Control flows] The objective of this chapter is to introduce the concepts of control flows and loops to the readers and show how to use them. Chapter 4: [Arrays] The objective of this chapter is to introduce the concept of arrays to the readers. It will also show how to declare and initialize arrays, and pass arrays to function. Chapter 5: [Slices] The objective of this chapter is to introduce the concept of slices to the readers and tell them how to declare slices, the various ways of creating slices, modifying and comparing slices, about multi-dimensional slices, sorting slices, and iterate over slices. Chapter 6: [Maps] This chapter explains the basic concept of map and how to use it in the Go programming language. It covers how to declare and
initialize a map, iterate over a map, how to perform retrieve, update, and delete over the map, and how to check if a key exists in a map, etc. Chapter 7: [Structs] This chapter explains the basic concept of struct and how to use it in the Go programming language. It covers how to declare and initialize structs type, access fields of structs, pointer to structs, exported and unexported structs, and structs fields. Chapter 8: [Methods] This chapter covers the concept of methods in the Go programming language. You will learn how to declare a method, how to call a method, the syntax of different types of methods, and the method resolution process. Chapter 9: [Interfaces] This chapter will cover the concept of interface in Golang. You will learn what the interface in Golang is, how Golang interfaces are different from other languages, how to declare an interface, and how implicit implementation happens in Golang and what are its benefits. We will create the interface without methods and see its benefits with built-in functions. We will see the impact of value receiver and pointer receiver while implementing the interface and creating polymorphic objects.
Chapter 10: [Pointers] In this chapter, you will learn what pointers in Golang are. This chapter will explain to you the use of pointers, how to declare a pointer variable, and you will understand the pointer types. You will also learn why arithmetic operations are not allowed on pointer variables in Golang. Chapter 11: [Concurrency] This chapter will cover goroutines and channels. You will learn how to define a goroutine, what WaitGroup is, and how to use the WaitGroup to wait for other goroutines to finish. You will understand the concept of channel. We will use the channel for communication between the goroutines. We will create two types of goroutines: buffered and unbuffered. Chapter 12: [Error handling] This chapter will cover error handling. At the end of this chapter, you will learn what an error in Golang is, how to return an error from a function or method, and how to handle these errors in the caller function. We will also see a built-in error interface, the error packages and the method, function, and struct in the errors package. You will learn how to define a new error, create a customized error type, what panic is, how to handle panic using recover, what defer is, and the importance of the defer function while handling panic, etc.
Downloading the coloured images: Please follow the link to download the Coloured Images of the book: https://rebrand.ly/xqrsibm Errata We take immense pride in our work at BPB Publications and follow best practices to ensure the accuracy of our content to provide with an indulging reading experience to our subscribers. Our readers are our mirrors, and we use their inputs to reflect and improve upon human errors, if any, that may have occurred during the publishing processes involved. To let us maintain the quality and help us reach out to any readers who might be having difficulties due to any unforeseen errors, please write to us at : errata@bpbonline.com Your support, suggestions and feedbacks are highly appreciated by the BPB Publications’ Family.
Did you know that BPB offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.bpbonline.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at business@bpbonline.com for more details. At you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on BPB books and eBooks.
BPB is searching for authors like you If you're interested in becoming an author for BPB, please visit www.bpbonline.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea. The code bundle for the book is also hosted on GitHub at In case there's an update to the code, it will be updated on the existing GitHub repository. We also have other code bundles from our rich catalog of books and videos available at Check them out! PIRACY If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at business@bpbonline.com with a link to the material. If you are interested in becoming an author
If there is a topic that you have expertise in, and you are interested in either writing or contributing to a book, please visit REVIEWS Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at BPB can understand what you think about our products, and our authors can see your feedback on their book. Thank you! For more information about BPB, please visit
Table of Contents 1. Introduction Structure Objective Introduction Why Go programming? 1.1 Data types 1.1.1 Numeric types 1.1.2 String types 1.1.3 Boolean types 1.1.4 Derived types 1.2 Constants 1.2.1 Variable declaration 1.2.2 Short variable declaration 1.3 Operator 1.3.1 Arithmetic operators 1.3.2 Relational operators 1.3.3 Logical operators 1.3.4 Bitwise operators 1.3.5 Assignment operators 1.4 Typed constants and untyped constants 1.4.1 Typed constants 1.4.2 Untyped constants 1.5 Multiple constant declarations 1.6 Redeclaration concept 1.7 Reassignment concept 1.8 Code structure Conclusion Questions
2. Functions Structure Objective 2.1 Function 2.1.1 Function declarations 2.2 Parameters and returns 2.2.1 Parameters 2.2.2 Returns 2.3 Multiple returns and named return 2.3.1 Multiple returns 2.3.2 Named returns 2.4 Call by value 2.4.1 Call by value 2.5 Variadic functions 2.6 Defer 2.6.1 Defer Conclusion Questions 3. Control flows Structure Objective 3.1 Decision-making 3.1.1 If statement 3.1.2 if…else statement 3.1.3 if…else if…else statement 3.1.4 switch…case 3.2 Loops 3.2.1 For loops
3.2.2 Nested for loops 3.2.3 Loop control statements 3.2.3.1 Break statements 3.2.3.2 Goto statements 3.2.3.3 Continue statements 3.2.3.4 Infinite loop 3.2.3.5 Fallthrough Conclusion Questions 4. Arrays Structure Objective 4.1 Arrays 4.2 Array declaration 4.2.1 Using var keyword 4.2.2 Shorthand declaration 4.3 Array initialization 4.4 2D and 3D array 4.5 Array iteration 4.6 Passing arrays to functions Conclusion Questions 5. Slices Structure Objective 5.1 Concept of slices 5.2 Declaration of slice 5.3 Creating a slice