Learning
Go Programming
Build Scalable Next-Gen
Web Application Using Golang
Shubhangi Agarwal
www.bpbonline.com
FIRST EDITION 2021
Copyright BPB Publications, India
ISBN: 978-93-89898-422
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 authors and publishers 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,
DN Rd. Next to Capital Cinema,
V.T. (C.S.T.) Station, MUMBAI-400
Ph: 22078296/22078297
DECCAN AGENCIES
4-3-329, Bank Street,
Hyderabad-500195
Ph: 24756967/24756400
BPB BOOK CENTRE
Old Lajpat Rai Market,
Delhi-110006
Ph: 23861747
Published by Manish Jain for BPB Publications, Ansari Road, Darya Ganj, New Delhi-110002 and Printed by him at Repro India Ltd, Mumbai
www.bpbonline.com
Dedicated to
My father
Dinesh Chandra Agarwal
&
My mother
Pushpa Agarwal
Who are always with me to love,
support, care and fix all the problems.
About the Author
Shubhangi Agarwal is an experienced software engineer, who for the past years has been working in information technology industry. In 2017, Shubhangi has started her career with market research industry, moving with IBM India pvt. Ltd., she is currently working as a senior software engineer with Tata Consultancy Services Ltd. In her career, Shubhangi has worked at multiple technologies such as Python, Golang and various backend development events. She is also working as a freelancer helping organizations in their projects and providing the same opportunities to others.
It was back in 2018 that Shubhangi got her taste for writing by her blogs. She shares her views on multiple programming languages, common tech problems & their solution and makes videos on technical content. Shubhangi loves working on latest technologies and sharing the technical insights through her website.
Outside work, Shubhangi loves blogging, photography, travelling, nature and spending time with her family and friends.
If you want to check out her blogs, please visit her website at http://momentmate.com/technical/
About the Reviewer
Deepak Sharma is a software developer with a demonstrated history of working in information technology and services industry. He holds a professional degree in Master of Computer Application from Dev Bhoomi Institute of Technology, Dehradun. After working as a data analyst, he is now developing multiple windows application in C, C++ and made a contribution in data & network encryption, HTTP, HTTPS & socket based applications. He was fortunate to review this book. When not programming, he enjoys watching movies and travelling.
Bhawana Bhatt is a solution-driven Software Engineer with four year of experience working with Motherson Sumi Systems Limited. She is handling various projects on .Net framework, JavaScript, jQuery, MVC, AngularJs and providing secure, scalable and tested solutions to her clients. She is a master degree holder in Computer Application from Gurukula Kangri Vishwavidyalaya. She is delighted to be part of this book as a technical reviewer. She always welcomes opportunities as well as technical challenges. She enjoys cooking, gardening, crafts and painting.
Acknowledgement
I want to thank God most of all, because without God I wouldnt be able to do any of this.
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 elder sisters, Shuchi and Chanchal who stood by me during every struggle and all my success. I could have never completed this book without their support.
My sincere thanks are due to few friends/TR of this book who encourages and motivate me every time and proves that they are always here for me. Such relations are the perfect example of Quality over Quantity.
This book wouldnt have happened if I hadnt had the support from content editor of BPB Publications. My gratitude goes to the editorial and publishing professionals of BPB Publications for their keen interest and support in bringing out this book
Finally, I would like to thank Manish Jain at BPB Publications for giving me this opportunity to write my first book for them.
Preface
Golang is developed by Robert Griesemer, Rob Pike, and Ken Thompson in 2007 at Google and publicly announced in November, 2009 as an open-source project. Golang has undergone many alterations and enhancements. Currently we have Go1.15 version that has released on August 2020. Each major Go release is supported until there are two newer major releases. Go is widely used in many organization LinkedIn, Twitter, IBM, Firefox, Docker, YouTube, Alibaba for back-end development.
This book is for the beginners as well as professionals who crave to learn Go language. This book highlights fundamental concepts you will need to learn to do Go programming. In this book, pictorial representation is given to clarify the concept and screenshots are there to describe the process, whenever necessary. To be an adequate Go programmer, a reader must learn it practically by running the programs as specified in this book. These programs will not only perform correctly but it is simple to write and understand. Comments are well mentioned with the programs that describes the purpose of specific statement/block. Output of specific program is thoroughly given so that one can verify it after running the code. Each chapter contain objective that describes how the specific chapter could be useful for a reader. At the end of each chapter, conclusion section refers brief or highlights content of the chapter and establish a link to the next chapter.