https://github.com/guidefari/snippetbox
https://github.com/guidefari/snippetbox
Last synced: over 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/guidefari/snippetbox
- Owner: guidefari
- Created: 2023-08-31T03:23:05.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-09-25T19:23:25.000Z (almost 3 years ago)
- Last Synced: 2025-04-02T02:44:29.327Z (over 1 year ago)
- Language: Go
- Size: 44.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
- Following the book [Let's Go](https://lets-go.alexedwards.net/)
- `chmod +x ./run.sh` if it refuses to execute
## TIL - Block action
> This acts like the {{template}} action, except it allows you to specify some default content if the template being invoked doesn’t exist in the current template set.
> In the context of a web application, this is useful when you want to provide some default content (such as a sidebar) which individual pages can override on a case-by-case basis if they need to.
```html
{{define "base"}}
An example template
{{block "sidebar" .}}
My default sidebar content
{{end}} {{end}}
```
## TIL - Additional info about Go's file server
- It sanitizes all request paths by running them through `path.Clean`
- this helps stop directory traversal attacks
- [Range requests](https://benramsey.com/blog/2008/05/206-partial-content-and-range-requests)
are fully supported. This is great for resumable downloads!
## TIL - All incoming http requests are handled concurrently
Yes, blazingly fast, but be aware of race conditions when accessing
shared resources
## TIL - Command line flags
`addrVariable := flag.String("addr", ":4000", "HTTP network address")`
- This takes the flag `addr` from the command line
- Sets a default value of `":4000"`
- Gives it some helper text
## Do a deep dive on function signatures
```go
// Change the signature of the home handler so it is defined as a method against // *application.
func (app *application) home(w http.ResponseWriter, r *http.Request) {
// as seen in handler.go
```
- my question is especially centered around `func (app *application)`
- learning module resolution and package management will probably be helpful tooo
- that \*application exists in `main.go`
## What is a struct, really?
- various use cases