وبلاگ بلیان

Let’s Go. Learn to build professional web applications with Go

معرفی کتاب «Let’s Go. Learn to build professional web applications with Go» نوشتهٔ Nelia Alarcon و A. Edwards، منتشرشده توسط نشر 2 در سال 2023. این کتاب در فرمت pdf، زبان انگلیسی ارائه شده است.

Contents Introduction Conventions About the author Copyright and disclaimer Prerequisites Background knowledge Go 1.20 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 SameSite cookies and TLS 1.3 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. Learn to build professional web applications with Go