Rumeel Hussain and Maryam Zulfiqar
Beginning Go Programming
Build Reliable and Efficient Applications with Go
The Apress logo.
Rumeel Hussain
Dubai, United Arab Emirates
Maryam Zulfiqar
Lahore, Pakistan
ISBN 978-1-4842-8857-3 e-ISBN 978-1-4842-8858-0
https://doi.org/10.1007/978-1-4842-8858-0
Rumeel Hussain and Maryam Zulfiqar 2022
Apress Standard
The use of general descriptive names, registered names, trademarks, service marks, etc. in this publication does not imply, even in the absence of a specific statement, that such names are exempt from the relevant protective laws and regulations and therefore free for general use.
The publisher, the authors and the editors are safe to assume that the advice and information in this book are believed to be true and accurate at the date of publication. Neither the publisher nor the authors or the editors give a warranty, express or implied, with respect to the material contained herein or for any errors or omissions that may have been made.
This Apress imprint is published by the registered company APress Media, LLC, part of Springer Nature.
The registered company address is: 1 New York Plaza, New York, NY 10004, U.S.A.
This book is dedicated to Rumeels late mother and Abdullah Hassan.
Preface
Google designed the Go language to be comprehensive yet be powerful enough to tackle big problems. It is a multi-paradigm programming language with built-in features for concurrent programming. It enables developers to easily build software that is simple, reliable, and efficient. This book is designed to provide knowledge to beginners and help them start developing great Go-based applications.
In this book, we cover the basics of the Go programming language and provide you with hands-on working experience through clear examples and recipes. From basic syntax formulation to providing insights into using the Go language to build concurrent programs and applications like HTTP servers and communication with REST APIs, this book covers it all.
This is a practical hands-on guide through which you will learn how to write Go code using clear examples that demonstrate the language in action. Youll also learn tips and tricks about the Go programming language for an efficient use.
Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub (https://github.com/Apress). For more detailed information, please visit http://www.apress.com/source-code.
Table of Contents
About the Authors
Rumeel Hussain
A photo of Rumeel Hussain.
has a bachelors degree in computer science and is presently working as a Blockchain Solution Architect at BNB Chain, supporting the development and growth of the BNB Chain ecosystem. He is an information technology enthusiast with more than five years of experience leading and implementing blockchain applications and architectures, analyzing and refactoring modern programming languages like Go, troubleshooting cloud infrastructure, and assessing security risks. His current work is focused on leveraging blockchain technology and crypto to achieve the full potential of Web3 applications.
Maryam Zulfiqar
has four years of research experience and has a masters degree in computer science. She is currently working as a Tech Martian at BNB Chain. She also works as a senior researcher and developer. She is passionate about developer education, especially about sharing her knowledge on topics that are the talk of the town in the technology field. She has also worked in researcher and teamlead roles for HEC-funded projects targeted at community growth and welfare.
About the Technical Reviewer
Fabio Claudio Ferracchiati
is a senior consultant and a senior analyst/developer using Microsoft technologies. He works for BluArancio ( www.bluarancio.com ). He is a Microsoft Certified Solution Developer for .NET, a Microsoft Certified Application Developer for .NET, a Microsoft Certified Professional, and a prolific author and technical reviewer. Over the past ten years, hes written articles for Italian and international magazines and coauthored more than ten books on a variety of computer topics.
The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2022
R. Hussain, M. Zulfiqar Beginning Go Programming https://doi.org/10.1007/978-1-4842-8858-0_1
1. Introduction
Rumeel Hussain
(1)
Dubai, United Arab Emirates
Developed by Google in 2007, Go (aka GoLang) is a programming language designed with simplicity and speed as its focus. The design goals of Go were to create a simple and readable syntax of a dynamically-typed, high-level language programming language like Python, but also have the stability and efficiency of a statically-typed low-level language like C/C++. Supported by Google, Go is an open-source programming language and is easier to learn and get started with. It has built-in support for concurrency, a robust standard library, type safety, multiple built-in types, dynamic-typing capability, garbage collection, and several other advanced features , such as key-value maps and variable-length arrays. Go has the power to let you leverage the might that multi-core processors have to offer, which results in faster-running programs.
Is GoLang Static-Typed or Compiled?
Any programmers natural concern about a programming language is whether the language is compiled or interpreted. JavaScript is an example of an interpreted language. Web browsers can directly read JavaScript source code and execute it at runtime. There is no pre-computation involved. Even though some interpreted environments can produce intermediate formats such as bytecode, there is no pre-computation step involved.
Compiled Programming Language
In contrast to an interpreted language, the source code of a compiled language is transformed into an operating system-specific format. Like C and C++, Go is a compiled language. However, compared to Java, whose source code is compiled into a format capable of running on different operating systems, Gos source code is compiled into an operating system-specific format. That means the code is executable only on the operating system for which it was compiled.
Statically-Typed Language
Go is a statically-typed language . That means its variables must have specific types. Nevertheless, it is not always mandatory to declare variables explicitly. The compiler can infer the types; however, at compilation time, the types are always known.
The capability to run a source code file without recompiling it can sometimes lead programmers to think that Go is an interpreted language. The real magic is in the background, where the source code is compiled into a temporary executable form. The compilation tool, Go, is required to build applications delivered to users. This is because the compiled executable is in a format that is operating-system-specific. Each Go application consists of a statically-linked runtime. During the compilation process of the application, a runtime component is packaged with the executable format. This is why the size of applications built using the Go language is comparatively larger than the source code. No external virtual machine is involved, so it is necessary to include a runtime package.