Previous Next

Golang for Jobseekers Unleash the power of Go programming for career advancement (Hairizuan Bin Noorazman) (z-library.sk, 1lib.sk, z-lib.sk)

Author: Hairizuan Bin Noorazman

GO

“Golang for Jobseekers” starts by providing a comprehensive introduction to Go, covering its syntax, fundamental concepts, and unique features that make it an efficient language for development. It delves deeply into data structures and algorithms, equipping you with techniques to optimize your code and solve complex problems with elegance and speed. Furthermore, the book explores the art of building robust RESTful API applications in Go. It teaches you industry best practices and architectural patterns for creating scalable, secure, and maintainable APIs. The book then takes you through a step-by-step journey from development to production, demonstrating how to deploy Go applications in different environments, ranging from virtual machines to containers on Kubernetes. Lastly, it helps you understand essential concepts like monitoring and logging, enabling you to ensure the performance and health of your applications in real-world scenarios.

📄 File Format: PDF
💾 File Size: 35.3 MB
10
Views
0
Downloads
0.00
Total Donations

📄 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.

📄 Page 1
(This page has no text content)
📄 Page 2
(This page has no text content)
📄 Page 3
Hairizuan Bin Noorazman www.bpbonline.com Golang for Jobseekers Unleash the power of Go programming for career advancement
📄 Page 4
ii  Copyright © 2023 BPB Online All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor BPB Online or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book. BPB Online has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, BPB Online cannot guarantee the accuracy of this information. First published: 2023 Published by BPB Online WeWork 119 Marylebone Road London NW1 5PU UK | UAE | INDIA | SINGAPORE ISBN 978-93-55518-538 www.bpbonline.com
📄 Page 5
 iii Dedicated to My beloved Parents: Noorazman Bin Bulat Jamilah Bte Yusof & My wife Nurwidayu
📄 Page 6
iv  About the Author Hairizuan Bin Noorazman has a degree in Chemical Engineering but switched over to Information Technology when he entered the workforce. He has worked on various technologies over the years and transitioned between multiple roles before working as a Devops Engineer in Acronis. He has 7+ years of experience in various domains like Software Development, DevOps Automation tools, and Web Analytics tools. In his spare time he writes blog posts and create videos on technical topics (e.g., usage of Golang/DevOps tools). He is also a Google Developer Expert (GDE) - a program by Google which recognizes individuals for contributing and sharing knowledge about Google technologies – in his case, it is mostly Google Cloud technologies.
📄 Page 7
 v About the Reviewers • Aakash Handa is a Full Stack Solution Architect, the crossover between design and programming has always been of interest to him. He has been lucky enough to work alongside some talented teams on a number of high-profile websites. He has a wide range of skills that include back-end development using open source technologies (NodeJs, Python, Go), design (working closely with designers), front-end development (Angular2, ReactJs, HTML5, CSS3, Javascript, Responsive, UX), Server Administrator(AWS, IBM, Azure), database(MongoDB, cassendra, Mysql), load balancing (Varnish and Memcached). • Prithvipal Singh is currently working as a Senior Software Engineer in Infoblox, where he is a core member of a DNS Firewall related project and working on projects developed as a cloud-native distributed system using Golang. He is the author of the Hands-on Go Programming book. He is an expert in distributed systems, cloud computing, and microservice architecture. He has been working in the IT industry for a decade and has vast experience working in Golang, Java, Docker, Kubernetes, Python, and Nodejs. He holds an MCA degree from Pune University.
📄 Page 8
vi  Acknowledgements There are a few people I want to thank for the continued and ongoing support they have given me during the writing of this book. First and foremost, I would like to thank my parents and my wife for continuously encouraging me to write the book — I could have never completed this book without their support. I am grateful to my current company Acronis which provided me with the environment to learn and develop the intuition for developing Golang applications and understand the end-to-end flow of developing applications and getting them into production. My gratitude also goes to the team at BPB Publication for being supportive during the book’s writing. I took a long while to write this book (since this was written during my off-hours outside work). It is particularly helpful to have someone who helps monitor the progress of the book and constantly checks in on the status of the book on a frequent basis.
📄 Page 9
 vii Preface After Python, the next programming language that appeals to users, primarily in the domain of Web application and software tooling, is Google’s Go language. It consistently ranks among the top 10 programming languages and aspires to be adopted by the larger developer community. This book is designed for fresh graduates or individuals with previous programming experience using C, Python, or Java. This book teaches the fundamental elements of Go by practicing and writing programs to get strong understanding of the elements. You will learn data types, protocols, data structures, and algorithms. The book will then introduce the reader to various aspects of the software engineering world, such as understanding REST APIs (one of the more common ways to structure web applications), deployment processes, and engineering practices of monitoring and logging applications. Chapter 1: Understanding Golang and its Potential – This chapter sets the stage and provides the motivation for the reader why to choose Golang to build their next app or why companies are taking up Golang nowadays Chapter 2: Golang Fundamentals – This chapter will cover a quick overview of how to get started with Golang. It is assumed that the reader already has experience with another programming language. Hence, a lot of things mentioned in this chapter would utilize common programming terms such as variables, types, functions, structs, and interface Chapter 3: Exploring Data Structures – This chapter will cover some of the Data Structures that are sometimes asked and tested during interview sessions for software engineering roles. Some of the concepts covered here are generally covered within the school syllabus/bootcamp syllabus, so it will mostly serve as a reminder of what some of these data structures are and how they can potentially be used (if any) Chapter 4: Understanding Algorithms – This chapter will cover some of the potential algorithm questions that could be covered in interview questions for a software engineer role. The chapter will cover some common ways to solve the algorithms using the Golang programming language as well as the time/space
📄 Page 10
viii  complexity that is related to the mentioned algorithm. It might not cover most cases but it should cover some of the more common concepts Chapter 5: Getting Comfortable with Go Proverbs – Unlike languages such as Java where consultants have outlined guidelines and design patterns that one could follow to design efficient and easy-to-understand code, Golang has a set of proverbs (thought up by community members) which would prove to be good guiding principles. Refer to the following webpage: https://go-proverbs.github. io/ Chapter 6: Building REST APIs – This chapter covers the basics of building web applications that follow REST API principles. Web applications are still one of the most common set of applications that are still being even now and would serve as a good basis before learning other possible protocols that pertain with web applications such as GRPC, thrift, and Graphql Chapter 7: Testing in Golang – Inform the reader of the importance of writing tests for Golang applications as well as how to do it – particularly important for junior roles especially since in many companies, unit tests/integrated tests are somewhat expected features to write up. Chapter 8: Deploying a Golang Application in a Virtual Machine – This chapter will cover how to get and run an application in a Virtual Machine. As much as applications are modernized by putting it into containers, not all applications should be containerized. Sometimes, due to security limitations or resource constraints, some of the applications are deployed in a Virtual machine. This chapter covers the various aspect of how to ensure a Golang application is copied over to the VM and then operated Chapter 9: Deploying a Containerized Golang Application – This chapter focuses less on Golang language specifics but on operations aspect of running the application. The technological have been moving in line with several trends such as containerization and DevOps – where developers should be responsible for containerizing their application. This chapter would cover how to do so and some of the hiccups that can happen for this
📄 Page 11
 ix Chapter 10: Microservices with Golang Applications – This is a chapter to cover microservices concept – which is a type of structure that many modern big companies would adopt. Generally, the microservices topic is pretty deep so this chapter will cover the topics on the “surface level”, enough such that someone would be able to start working in situations where applications are deployed in microservices architectures Chapter 11: Introduction to Monitoring and Logging – Building an application that provides just the required functionality is nowadays insufficient. We would want to understand and assure ourselves that our application is working fine and in a responsive manner. In order to get such information, we would need to add monitoring and logging to the application. This chapter would cover the details of it so that it would allow us to understand how the application is operating but from an external lens Chapter 12: Adding Concurrency in Golang Application – One of the main draws of Golang applications is the capability to write up applications that can be concurrent in nature, however, it has not been the focus of this book. One main reason is because YAGNI; if you can avoid using it, you should – it introduces a whole bunch of complexity to the program, making it way harder to debug and understand. However, there are still certain scenarios that might be useful to have such capabilities Chapter 13: What is Next? – This chapter will cover possible points for the reader to continue exploring in order to understand the Golang language and the technology industry. There are various topics that branch out and require in-depth study in order to understand how to write effective code for such domain spaces. Some of the topics covered such as GRPC, Application Profiling and Generics
📄 Page 12
x  Code Bundle and Coloured Images Please follow the link to download the Code Bundle and the Coloured Images of the book: https://rebrand.ly/ck0bvsw The code bundle for the book is also hosted on GitHub at https://github.com/ bpbpublications/Golang-for-Jobseekers. In case there’s an update to the code, it will be updated on the existing GitHub repository. We have code bundles from our rich catalogue of books and videos available at https://github.com/bpbpublications. Check them out! 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 www.bpbonline.com, 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.
📄 Page 13
 xi 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 www.bpbonline.com. We have worked with thousands of developers and tech professionals, just like you, to help them share their insights 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. 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 www.bpbonline.com. Join our book's Discord space Join the book's Discord Workspace for Latest updates, Offers, Tech happenings around the world, New Release and Sessions with the Authors: https://discord.bpbonline.com
📄 Page 14
xii  Table of Contents 1. Understanding Golang and its Potential ....................................................... 1 Introduction .............................................................................................................. 1 Structure .................................................................................................................... 1 Objectives .................................................................................................................. 2 Characteristics of Golang Programming Language ............................................ 2 Statically typed .................................................................................................. 3 Garbage collection ............................................................................................. 4 Cross-compilation ............................................................................................. 6 “Batteries Included” standard library ............................................................... 6 Version guarantees ............................................................................................ 7 What kind of development work is Golang used in? .......................................... 8 Web applications ............................................................................................... 8 Command Line Interface (CLI) ....................................................................... 9 Major applications written with Golang ............................................................... 9 Docker.............................................................................................................. 10 Kubernetes ....................................................................................................... 11 CockroachDB................................................................................................... 12 Companies that use Golang .................................................................................. 13 Cloudflare ................................................................................................................ 13 Monzo .............................................................................................................. 14 Conclusion .............................................................................................................. 15 2. Golang Fundamentals ...................................................................................17 Introduction ............................................................................................................ 17 Structure .................................................................................................................. 17 Objectives ................................................................................................................ 18 Golang playground ................................................................................................ 18 Installing and running Golang locally................................................................. 19 Main function in main package ........................................................................... 20 Imports .................................................................................................................... 21 Variable initialization............................................................................................. 24
📄 Page 15
 xiii Basic types ............................................................................................................... 25 List ............................................................................................................................ 28 Maps ......................................................................................................................... 32 Writing functions ................................................................................................... 33 Structs ...................................................................................................................... 39 Interfaces ................................................................................................................. 44 Loops........................................................................................................................ 48 Public versus private .............................................................................................. 53 Using “Go” verb ...................................................................................................... 56 Channels .................................................................................................................. 60 Errors ....................................................................................................................... 61 Conclusion .............................................................................................................. 63 3. Exploring Data Structures ............................................................................65 Introduction ............................................................................................................ 65 Structure .................................................................................................................. 65 Objectives ................................................................................................................ 66 Singly linked list ..................................................................................................... 66 Doubly linked list ................................................................................................... 76 Circular linked list.................................................................................................. 79 Stack ......................................................................................................................... 81 Queue....................................................................................................................... 83 Binary tree ............................................................................................................... 85 Hashed maps ........................................................................................................... 89 Conclusion .............................................................................................................. 93 4. Understanding Algorithms ...........................................................................95 Introduction ............................................................................................................ 95 Structure .................................................................................................................. 95 Objectives ................................................................................................................ 96 Big O notation ........................................................................................................ 96 Sorting algorithms and their importance ........................................................... 99 Bubble sort .............................................................................................................. 99 Merge sort ............................................................................................................. 103
📄 Page 16
xiv  Quick sort .............................................................................................................. 107 Binary search ........................................................................................................ 112 Dynamic programming ....................................................................................... 114 Conclusion ............................................................................................................ 119 5. Getting Comfortable with Go Proverbs .....................................................121 Introduction .......................................................................................................... 121 Structure ................................................................................................................ 122 Objectives .............................................................................................................. 122 e bigger the interface, the weaker the interface ........................................... 122 Make the zero value useful .................................................................................. 123 interface{} says nothing ....................................................................................... 124 Gofmt’s style is no one’s favorite, yet everyone’s favorite................................. 125 Errors are values ................................................................................................... 128 Do not just check errors, handle them gracefully ............................................ 129 Documentation is for users................................................................................. 130 Do not panic ......................................................................................................... 132 Accept interfaces, return structs ........................................................................ 135 Never use global variables ................................................................................... 139 Conclusion ............................................................................................................ 141 6. Building REST APIs ....................................................................................143 Introduction .......................................................................................................... 143 Structure ................................................................................................................ 144 Objectives .............................................................................................................. 144 Why learn to build REST APIs? ......................................................................... 144 HTTP verbs........................................................................................................... 146 HTTP status codes ............................................................................................... 148 Building a “Hello World” REST API Golang application ............................... 150 Building a URL shortener ................................................................................... 155 Conclusion ............................................................................................................ 178 7. Testing in Golang ........................................................................................181 Introduction .......................................................................................................... 181 Structure ................................................................................................................ 182
📄 Page 17
 xv Objectives .............................................................................................................. 182 Why build tests? ................................................................................................... 182 Test-driven development..................................................................................... 183 Writing a simple unit test .................................................................................... 184 Table driven tests .................................................................................................. 187 Mocking................................................................................................................. 194 Setup and teardown of environments within tests .......................................... 200 HTTP testing ........................................................................................................ 206 Golden files ........................................................................................................... 209 Conclusion ............................................................................................................ 210 8. Deploying a Golang Application in a Virtual Machine .............................211 Introduction .......................................................................................................... 211 Structure ................................................................................................................ 212 Objectives .............................................................................................................. 212 Using SSH.............................................................................................................. 213 Using SCP.............................................................................................................. 220 Using Systemd to run the Golang application .................................................. 226 Debugging the Golang application on the server ............................................ 231 Real-life deployments with virtual machines ................................................... 233 Conclusion ............................................................................................................ 235 9. Deploying a Containerized Golang Application ........................................237 Introduction .......................................................................................................... 237 Structure ................................................................................................................ 238 Objectives .............................................................................................................. 238 Docker basics ........................................................................................................ 238 Docker command basics ..................................................................................... 241 Building a Golang application in a Docker container ..................................... 250 Using Docker compose on a local workstation ................................................ 264 Using docker-compose on a virtual machine ................................................... 274 Deploying the application via Kubernetes ........................................................ 280 Conclusion ............................................................................................................ 287
📄 Page 18
xvi  10. Microservices with Golang Applications ...................................................289 Introduction .......................................................................................................... 289 Structure ................................................................................................................ 290 Objectives .............................................................................................................. 290 What are microservices, and why are microservices? ..................................... 290 Demo-ing an application stack with multiple applications via docker-compose ................................................................................................... 294 Demo-ing an application with multiple applications in Kubernetes............. 316 Conclusion ............................................................................................................ 329 11. Introduction to Monitoring and Logging ..................................................331 Introduction .......................................................................................................... 331 Structure ................................................................................................................ 332 Objectives .............................................................................................................. 332 Why monitoring and logging are important? .................................................. 332 Introduction to Prometheus ............................................................................... 334 Instrumenting an application with metrics to be consumed by Prometheus ................................................................................... 336 Viewing metrics on Prometheus ........................................................................ 341 Quick word on logging ....................................................................................... 348 Conclusion ............................................................................................................ 349 12. Adding Concurrency in Golang Application .............................................351 Introduction .......................................................................................................... 351 Structure ................................................................................................................ 352 Objectives .............................................................................................................. 352 Concurrency features in Golang ........................................................................ 352 Exchanging messages and persisting it locally ................................................. 355 Using channels to receive interrupts in a program .......................................... 358 Live reload of configurations .............................................................................. 361 Parallelize parts of an application ...................................................................... 364 Conclusion ............................................................................................................ 368 13. What is Next? ..............................................................................................369 Introduction .......................................................................................................... 369
📄 Page 19
 xvii Structure ................................................................................................................ 369 Objectives .............................................................................................................. 370 GRPC—alternative communication protocols ................................................ 370 SRE principles for reliable applications ............................................................. 374 Profiling ................................................................................................................. 375 Working with data storage .................................................................................. 378 Embedding files .................................................................................................... 382 Generics ................................................................................................................. 384 Fuzzing .................................................................................................................. 386 Conclusion ............................................................................................................ 388 Index ..................................................................................................................389
📄 Page 20
(This page has no text content)
The above is a preview of the first 20 pages. Register to read the complete e-book.

💝 Support Author

0.00
Total Amount (¥)
0
Donation Count

Login to support the author

Login Now

Recommended for You

Loading recommended books...
Failed to load, please try again later
Back to List