Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: Jon Calhoun

Rating No ratings yet

No description

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
【One-Line Pitch】 A hands-on, project-driven guide to building a real web application in Go—routing, templates, databases, authentication, and security—for developers who know some Go and want to ship a working site rather than just study syntax. 【Book Arc】 - **Opening (~0%–10%)**: Bootstraps a minimal HTTP server, adds a custom router and 404 handling, and introduces the MVC mental model plus the request lifecycle. - **Early (~10%–32%)**: Builds the view layer with `html/template`, reusable Bootstrap layouts and named templates, then wires up the first controller and form processing with struct tags. - **Middle (~32%–48%)**: Introduces PostgreSQL and GORM, models users and orders, and refactors data access behind a `UserService` interface with query methods. - **Late (~48%–60%)**: Implements authentication—password hashing, login/logout flows, and the security reasoning behind each step. - **Ending (~60%+)**: Covers persistent sessions via remember tokens, HMAC signing, cookie hardening against XSS and theft, and CSRF prevention, closing with exercises. 【Key Takeaways】 - **The book teaches through one continuous project** (Opening): concepts arrive as features you add to a single app, so learning is cumulative rather than isolated snippets. - **Routing is built from scratch before frameworks** (Opening): understanding `HandlerFunc`, method matching, and path parsing makes later framework use less magical. - **`html/template` is a security choice, not just a convenience** (Early): its auto-escaping defends against code injection, unlike `text/template`. - **Reusable layouts and named templates keep views maintainable** (Early): a shared Bootstrap shell lets individual pages focus on content. - **Struct tags bridge forms, models, and databases** (Early): metadata like `schema` and `gorm` keys drives mapping without manual glue code. - **Data access belongs behind a service layer** (Middle): the `UserService` interface isolates queries and makes the rest of the app easier to reason about. - **Password handling requires deliberate separation** (Middle): storing a hash-only field and a non-persisted raw field prevents accidental double-hashing or plaintext leaks. - **Cookie security is layered** (Ending): HMAC signing detects tampering, while XSS, theft, and CSRF each need their own mitigation. 【Reading Tips】 - Deep-read the routing and template chapters; they underpin everything later and are where Go's standard library shines. - Skim the Bootstrap/CSS asides—they're about speed, not concepts—but don't skip the security boxes. - Treat the exercises (especially the "HARD" ones) as required; they force you to extend the service layer yourself. - When you hit GORM, pause to understand `AutoMigrate`'s limits before relying on it. - Keep the running app open in a browser as you read; the book is designed to be typed along with. 【Coverage Limits】 The excerpts cover roughly the first half of the book plus the authentication/session chapters; later deployment, testing, and any advanced topics are not represented here.
Excerpt 1
in the terminal where you ran go run main.go. 26 CHAPTER 3. ADDING NEW PAGES w.WriteHeader(http.StatusNotFound) fmt.Fprint(w, "<h1>We could not find the page...
View in text
Excerpt 2
receive from our call to Glob. Box 6.6. Why so many panics? At this point I want to address the question, “Why are we panicking so much in view.go?” Aren’t p...
View in text
Excerpt 3
b.Close() db.AutoMigrate(&User{}) } You can also use the db.AutoMigrate function to update models. For exam- ple, if we added the Age int attribute to the Us...
View in text
Excerpt 4
ges we are done adding the login page and are ready to move on to implementing the Authenticate method for our user service. Source code The links below have...
View in text
Excerpt 5
ection in Appendix 18.1, then come back here. In Listing 12.1 we looked at how we might define our layers using structs, and we spoke briefly about how this...
View in text
Excerpt 6
dea to focus on this until you settle on a user experience. There are four types of alert: success, info, warning, and danger. The only difference between th...
View in text
Excerpt 7
e that in the next section then come back to finish our Up- date handler. In the meantime, we are rendering the edit page again with the submitted data and a...
View in text
Excerpt 8
he create method isn’t going to accept an Image struct type as its only argument, and is instead going to accept the data needed to create an image. What dat...
View in text
Tags
AI categories
GoWeb TechnologyBackend
Publisher: usegolang.com
Publish Year: 2016
Language: English
Pages: 747
File Format: PDF
File Size: 8.0 MB
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.

Generating text preview…