وبلاگ بلیان

Let's Go

معرفی کتاب «Let's Go» نوشتهٔ Alex Edwards، منتشرشده توسط نشر alexedwards.net در سال 2022. این کتاب در فرمت pdf، زبان انگلیسی ارائه شده است. «Let's Go» در دستهٔ برنامه‌نویسی قرار دارد.

Go is a great language for building web applications. But teaching yourself from blog posts and the standard library documentation can be a big time-sink and leave you with more questions than answers. You might be wondering things like: Where can I see a concrete example of a real-world web application? How is it best to structure and organize my code? How do I manage and version control dependencies? And how do I effectively test my web application? Let’s Go answers these questions for you — and a whole lot more — helping you get up to speed quickly and saving you months of research and experimentation. The book walks through the start-to-finish build of a complete working application, helping you to learn by doing. You’ll get practical experience implementing common real-life code patterns, the topics that you’re learning about are put in context, and you'll end up with a well-structured codebase that you can adapt for your own future work. By the end of the book, you’ll have all the knowledge and confidence that you need to build your own professional, production ready, web applications. So grab your copy, break out your text editor, and happy coding! Contents Introduction Conventions About the author Copyright and disclaimer Prerequisites Background knowledge Go 1.18 Other software Foundations Project setup and creating a module Creating a module Hello world! Additional information Module paths for downloadable packages Web application basics Additional information Network addresses Using go run Routing requests Fixed path and subtree patterns Restricting the root url pattern The DefaultServeMux Additional information Servemux features and quirks Host name matching What about RESTful routing? Customizing HTTP headers HTTP status codes Customizing headers The http.Error shortcut The net/http constants Additional information System-generated headers and content sniffing Manipulating the header map Header canonicalization Suppressing system-generated headers URL query strings The io.writer interface Project structure and organization Refactoring your existing code Additional information The internal directory HTML templating and inheritance Template composition Embedding partials Additional information The block action Embedding files Serving static files The http.Fileserver handler Using the static files Additional information Features and functions Performance Serving single files Disabling directory listings The http.Handler interface Handler functions Chaining handlers Requests are handled concurrently Configuration and error handling Managing configuration settings Command-line flags Default values Type conversions Automated help Additional information Environment variables Boolean flags Pre-existing variables Leveled logging Decoupled logging The http.Server error log Additional information Additional logging methods Concurrent logging Logging to a file Dependency injection Adding a deliberate error Additional information Closures for dependency injection Centralized error handling Revert the deliberate error Isolating the application routes Database-driven responses Setting up MySQL Scaffolding the database Creating a new user Test the new user Installing a database driver Modules and reproducible builds Additional information Upgrading packages Removing unused packages Creating a database connection pool Usage in our web application Testing a connection Designing a database model Using the SnippetModel Additional information Benefits of this structure Executing SQL statements Executing the query Using the model in our handlers Additional information Placeholder parameters Single-record SQL queries Using the model in our handlers Additional information Checking for specific errors Shorthand single-record queries Multiple-record SQL queries Using the model in our handlers Transactions and other details The database/sql package Verbosity Managing null values Working with transactions Prepared statements Dynamic HTML templates Displaying dynamic data Rendering multiple pieces of data Additional information Dynamic content escaping Nested templates Calling methods Html comments Template actions and functions Using the with action Using the if and range actions Additional information Combining functions Controlling loop behavior Caching templates Automatically parsing partials Catching runtime errors Common dynamic data Custom template functions Additional information Pipelining Middleware How middleware works The pattern Simplifying the middleware Positioning the middleware Setting security headers Additional information Flow of control Early returns Debugging CSP issues Request logging Panic recovery Additional information Panic recovery in other background goroutines Composable middleware chains Advanced routing Choosing a router Clean URLs and method-based routing Custom error handlers Additional information Conflicting route patterns Customizing httprouter behavior Restful routing Handler naming Processing forms Setting up a HTML form Parsing form data Additional information The r.Form map The FormValue and PostFormValue methods Multiple-value fields Limiting form size Validating form data Displaying errors and repopulating fields Updating the HTML template Creating validation helpers Adding a validator package Using the helpers Automatic form parsing Using the form decoder Creating a decodePostForm helper Stateful HTTP Choosing a session manager Setting up the session manager Additional information Without using alice Working with session data Auto-displaying flash messages Additional information Behind-the-scenes of session management Security improvements Generating a self-signed TLS certificate Running a HTTPS server Additional information HTTP requests HTTP/2 connections Certificate permissions Source control Configuring HTTPS settings Additional information TLS versions Restricting cipher suites Connection timeouts The IdleTimeout setting The ReadTimeout setting The WriteTimeout setting Additional information The ReadHeaderTimeout setting The MaxHeaderBytes setting User authentication Routes setup Creating a users model Building the model in Go User signup and password encryption Validating the user input A brief introduction to bcrypt Storing the user details Additional information Using database bcrypt implementations Alternatives for checking email duplicates User login Verifying the user details User logout User authorization Restricting access Additional information Without using alice CSRF protection SameSite cookies Token-based mitigation Using the nosurf package Additional information SameSite ‘Strict’ setting Using request context How request context works The request context syntax Avoiding key collisions Request context for authentication/authorization Additional information Misusing request context Optional Go features Using embedded files Using the static files Embedding HTML templates Using generics When to use generics Using generics in our application Testing Unit testing and sub-tests Creating a unit test Table-driven tests Helpers for test assertions Additional information Sub-tests without a table of test cases Testing HTTP handlers and middleware Recording responses Testing middleware End-to-end testing Using httptest.Server Using test helpers Cookies and redirections Customizing how tests run Controlling which tests are run Test caching Fast failure Parallel testing Enabling the race detector Mocking dependencies Mocking the database models Initializing the mocks Testing the snippetView handler Testing HTML forms Testing post requests Integration testing Test database setup and teardown Testing the UserModel.Exists method Skipping long-running tests Profiling test coverage Conclusion Let's Go Further Further reading and useful links Coding and style guidelines Recommended tutorials Third-party package lists Guided exercises Add an ‘About’ page to the application Step 1 Step 2 Step 3 Step 4 Suggested code Suggested code for step 1 Suggested code for step 2 Suggested code for step 3 Suggested code for step 4 Add a debug mode Step 1 Step 2 Step 3 Suggested code Suggested code for step 1 Suggested code for step 2 Test the snippetCreate handler Step 1 Step 2 Step 3 Suggested code Suggested code for step 1 Suggested code for step 2 Suggested code for step 3 Add an ‘Account’ page to the application Step 1 Step 2 Step 3 Step 4 Step 5 Suggested code Suggested code for step 1 Suggested code for step 2 Suggested code for step 3 Suggested code for step 4 Suggested code for step 5 Redirect user appropriately after login Step 1 Step 2 Suggested code Suggested code for step 1 Suggested code for step 2 Implement a ‘Change Password’ feature Step 1 Step 2 Step 3 Step 4 Step 5 Step 6 Step 7 Suggested code Suggested code for step 1 Suggested code for step 2 Suggested code for step 3 Suggested code for step 4 Suggested code for step 5 Suggested code for step 6 Suggested code for step 7 Let’s Go teaches you step-by-step how to create fast, secure and maintainable web applications using the fantastic programming language Go.The idea behind this book is to help you learn by doing. Together we’ll walk through the startto-finish build of a web application — from structuring your workspace, through to session management, authenticating users, securing your server and testing your application.Building a complete web application in this way has several benefits. It helps put the things you’re learning into context, it demonstrates how different parts of your codebase link together, and it forces us to work through the edge-cases and difficulties that come up when writing software in real-life. In essence, you’ll learn more than you would by just reading Go’s (great) documentation or standalone blog posts.By the end of the book you’ll have the understanding — and confidence — to build your own production-ready web applications with Go.Although you can read this book cover-to-cover, it’s designed specifically so you can follow along with the project build yourself.Break out your text editor, and happy coding!— Alex
دانلود کتاب Let's Go