Cover Page....2
Title Page....3
Copyright Page....4
Foreword....5
Dedication Page....6
About the Author....7
Technical Reviewers....8
Acknowledgements....9
Preface....10
Errata....12
Table of Contents....15
1. Basic Concepts of Go Programming Language....24
Introduction....24
Structure....24
Fundamentals of Go programming language....24
Advantages of Go programming language....25
Go Playground....26
Keywords....27
Packages....28
Basic data types....29
Variables....31
Type conversion....32
Constants....32
Complex data types....34
Pointers....34
Struct....35
Arrays....37
Maps....39
Control structures....40
If statement....41
Switch statement....42
For loop....43
Defer....45
Functions....47
Conclusion....52
References....52
Points to remember....52
Multiple choice questions....53
Answers....54
Questions....54
Key terms....55
2. Advanced Concepts of Go Programming Language....57
Introduction....57
Structure....57
Methods....57
Interfaces....59
Generics....62
Panics....63
Concurrency....64
Goroutines....64
Channels....65
Mutex....67
WaitGroup....68
Go Scheduler....70
Garbage collector....71
Go modules....72
Conclusion....73
Points to remember....73
Multiple choice questions....74
Answers....75
Questions....75
Key terms....75
3. Web Servers....77
Introduction....77
Structure....77
Servers....77
Web servers....79
Proxies....81
REST....82
HTTP....84
HTTP flow....85
HTTP messages....85
HTTP methods....87
HTTP status codes....87
Additional functionalities....89
HTTP and REST....89
JSON....89
JSON and Go....91
Routing....92
Conclusion....93
Points to remember....94
Multiple choice questions....94
Answers....95
Questions....95
Key terms....96
4. Setting up a Project With Go Programming Language....97
Introduction....97
Structure....97
Go installation....98
Linux....98
Windows....99
Mac....100
Setting up an IDE....101
IDE installation....101
Visual Studio Code extension for Go....101
Project creation....103
Package creation....105
Standard library....107
Third-party libraries....116
net/http package....118
Constants....118
Variables....120
Functions....122
Types....124
Simple HTTP server....125
Conclusion....126
References....127
Points to Remember....127
Multiple choice questions....127
Answers....128
Questions....128
Key terms....128
5. Design of Web Application....130
Introduction....130
Structure....130
Software development life cycle (SDLC)....131
General approaches for application design....132
Micro-kernel (plug-in) design pattern....133
Command and Query Responsibility Segregation (CQRS) design pattern....135
Combine (hybrid) design pattern....136
Layered design pattern....137
Controller (handler) layer: handling HTTP requests....139
Service (core) layer: business logic....140
Repository (data) layer: queries and database operations....141
Database layer....141
Planning phase....141
Defining business requirements....142
Defining use cases....143
Design phase....143
High-level system design....144
API design....145
Database design....147
Conclusion....149
Points to remember....149
Multiple choice questions....149
Answers....150
Questions....151
Key terms....151
6. Application Layers....153
Introduction....153
Structure....153
Code organization....154
Models....155
Main function....157
Configuration....158
HTTP server....162
Initialization....163
Start....165
Development of controller layer....165
Runners controller....166
Results controller....171
Development of service layer....173
Runners service....173
Results service....180
Conclusion....186
References....186
Points to remember....186
Multiple choice questions....187
Answers....187
Questions....188
Key terms....188
7. Relational Databases and Repository Layer....189
Introduction....189
Structure....189
Relational databases....190
SQL....192
SELECT command....193
Modification commands....194
Aggregate functions....195
JOIN....196
Table definition commands....197
PostgreSQL....199
Setting up a database....199
Repository layer....210
Database layer....233
MySQL....235
Setting up a database....235
Repository layer....243
Database layer....248
Improvements....249
Conclusion....250
References....250
Points to remember....250
Multiple choice questions....251
Answers....251
Questions....252
Key terms....252
8. NoSQL Databases and Repository Layer....253
Introduction....253
Structure....253
NoSQL databases....254
MongoDB....254
Database design....256
Read operations....256
Write operations....260
Aggregation pipeline....263
Setting up a database....265
Repository layer....272
Database layer....293
DynamoDB....295
Database design....297
Read operations....298
Write operations....301
Setting up a database....305
Repository layer....310
Database layer....328
Improvements....335
Conclusion....336
References....337
Points to remember....337
Multiple choice questions....337
Answers....338
Questions....338
Key terms....338
9. Testing....340
Introduction....340
Structure....340
Testing fundamentals....340
Manual testing....342
Testing with Go....344
Unit tests....345
Integration tests....350
Testing with Visual Studio Code....355
Conclusion....357
References....357
Points to remember....357
Multiple choice questions....358
Answers....358
Questions....359
Key terms....359
10. Security....360
Introduction....360
Structure....360
Authentication and authorization....360
API design....363
Database design....364
Models....365
HTTP server....365
Controller layer....367
Users controller....367
Other controllers....370
Service layer....371
Setting up a database....376
Repository layer....377
Testing....382
Conclusion....384
Points to remember....384
Multiple choice questions....385
Answers....385
Questions....385
Key terms....386
11. Deploying Web Application....387
Introduction....387
Structure....387
Docker....388
Setting up Docker....390
Docker commands....391
Dockerizing application....393
Docker compose....395
Kubernetes....397
Setting up a local Kubernetes cluster....398
Kubectl commands....402
Deploying on Kubernetes....403
Google Cloud Platform....410
Setting up a database....410
Deployment of a web server application....413
Conclusion....416
References....417
Points to remember....417
Multiple choice questions....417
Answers....418
Questions....418
Key terms....418
12. Monitoring and Alerting....419
Introduction....419
Structure....419
Prometheus....419
Prometheus query language....421
Setting up Prometheus....423
Custom Prometheus metrics....424
Grafana....430
Setting up Grafana....430
Creating Grafana dashboard....435
Alerting....441
Conclusion....442
References....442
Points to remember....442
Multiple choice questions....443
Answers....443
Questions....444
Key terms....444
Index....445
In this book, we are going to learn how to design, develop and deploy Web Server Applications using the Go programming language. In recent years, Go has become the industrial standard for these kinds of applications; so by learning this, a lot of good opportunities can be opened in the market. All subjects will be covered through various practical examples.
This book will cover the state-of-the-art technology for the development of Web Applications and follow all industrial standards. At the beginning we will do the preparation for development. Here, we will learn the basics of the Go programming language, the basics of Web Servers, how to set up a project with Go, and how to design software solutions.
Later, we will concentrate more on development. We will learn how to develop the application designed in the previous chapters, how to use different types of databases, how to test our application, and how to make it secure. At the end of the book, we will show how to deploy the application and monitor it after deployment.
After reading this book, the readers can independently develop Web Server Applications or include themselves in already-started projects.
The book is for beginners and experienced developers who want to learn and have a thorough introduction to web development using the Go programming language. With a lot of practical examples and guidelines on how to install and configure specific tools, beginners will easily understand and follow the content covered in this book. On the other hand, more experienced developers will certainly find some useful tips and tricks.