-
Go - go install
摘要:zzh@ZZHPC:/zdata/Github/greenlight$ go install honnef.co/go/tools/cmd/staticcheck no required module provides package honnef.co/go/tools/cmd/staticche
阅读全文
-
Sed - Extract help usage from comments
摘要:Makefile: ## help: print this help message help: @echo 'Usage:' @sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /' confirm: @ech
阅读全文
-
Let'sGoFurther - Chapter 19: Building, Versioning and Quality Control
摘要: makemigrationname=createexampletablerun:gorun./cmd/apipsql:psql{GREENLIGHT_DB_DSN} migration: @echo 'Creating migration files for ${name
阅读全文
-
Let'sGoFurther - Chapter 18: Metrics
摘要:In routes.go: router.Handler(http.MethodGet, "/debug/vars", expvar.Handler()) func main() { expvar.NewString("version").Set(version) ... func main() {
阅读全文
-
Let'sGoFurther - Chapter 17: Cross Origin Requests
摘要:package main import ( "log" "net/http" ) const html = ` <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> </head> <body> <h1>Simple CORS<
阅读全文
-
Let'sGoFurther - Chapter 16: Permission-based Authorization
摘要:In errors.go: func (app *application) authenticationRequiredResponse(w http.ResponseWriter, r *http.Request) { message := "you must be authenticated t
阅读全文
-
Let'sGoFurther - Chapter 15: Authentication
摘要:const ( ScopeActivation = "activation" ScopeAuthentication = "authentication" ) // Token holds the data for a token. type Token struct { Plaintext str
阅读全文
-
Let'sGoFurther - Chapter 14: User Activation
摘要:zzh@ZZHPC:/zdata/Github/greenlight$ migrate create -seq -ext .sql -dir ./migrations create_token_table /zdata/Github/greenlight/migrations/000005_crea
阅读全文
-
Viper - Watch and reload configuration from config files
摘要:How to change the cnfiguration for rate limiting in flight? How to change the configuration of pgxpool without restarting the application? How to dyna
阅读全文
-
Go - Get current directory of a source file
摘要:package main import ( "fmt" "os" ) func main() { fmt.Println(os.Executable()) fmt.Println(os.Getwd()) } zzh@ZZHPC:~/zd/Github/ztest$ go run main.go /t
阅读全文
-
Let'sGoFurther - Chapter 13: Sending Emails
摘要:zzh@ZZHPC:~ curl−w′\nTime:BODY" localhost:4000/v1/users { "user": { "id": 6, "created_at": "2024-11-21T18:33:14+08:00", "nam
阅读全文
-
Let'sGoFurther - Chapter 12: User Model Setup and Registration
摘要:zzh@ZZHPC:/zdata/Github/greenlight$ migrate create -seq -ext=.sql -dir=./migrations create_user_table /zdata/Github/greenlight/migrations/000004_creat
阅读全文
-
Let'sGoFurther - Chapter 11: Graceful Shutdown
摘要:zzh@ZZHPC:/zdata/Github/greenlight$ go run ./cmd/api time=2024-11-18T19:49:43.864+08:00 level=INFO msg="database connection pool established" time=202
阅读全文
-
Let'sGoFurther - Chapter 10: Rate Limiting
摘要:zzh@ZZHPC:/zdata/Github/greenlight$ go get golang.org/x/time/rate@latest go: downloading golang.org/x/time v0.8.0 go: added golang.org/x/time v0.8.0 f
阅读全文
-
Let'sGoFurther - Chapter 9: Filtering, Sorting, and Pagination
摘要:zzh@ZZHPC:~$ curl "localhost:4000/v1/movies?title=godfather&genres=crime,drama&page=1&page_size=5&sort=year" {Title:godfather Genres:[crime drama] Pag
阅读全文
-
Let'sGoFurther - Chapter 8: Advanced CRUD Operations
摘要:var ( ErrRecordNotFound = errors.New("record not found") ErrEditConflict = errors.New("edit conflict") ) // Update updates a specific record in the mo
阅读全文
-
Let'sGoFurther - Chapter 7: CRUD Operations
-
Let'sGoFurther - Chapter 6: SQL Migrations
摘要:Installing the migrate tool To manage SQL migrations in this project we’re going to use the migrate command-line tool (which itself is written in Go).
阅读全文
-
Let'sGoFurther - Chapter 5: Database Setup and Configuration
摘要:zzh@ZZHPC:/zdata/Github/greenlight dockerpullpostgreszzh@ZZHPC:/zdata/Github/greenlight docker run --name postgres17 -p 5432:5432 -e POSTGRES_USE
阅读全文
-
Go - Create a struct with another struct's fields
摘要:package main import ( "fmt" ) type A struct { field1 string } type B struct { field1 string } func main() { a := A{ field1: "aaa", } b := B(a) fmt.Pri
阅读全文
-
Let'sGoFurther - Chapter 4: Parsing JSON Requests
摘要:func (app *application) exampleHandler(w http.ResponseWriter, r *http.Request) { var input struct { Foo string `json:"foo"` } // Use io.ReadAll() to r
阅读全文
-
Go - JSON Decoding Nuances
-
Go - JSON Encoding Nuances
-
Let'sGoFurther - Chapter 3: Sending JSON responses
摘要:func (app *application) writeJSON(w http.ResponseWriter, status int, data envelope, headers http.Header) error { js, err := json.MarshalIndent(data, "
阅读全文
-
Let'sGoFurther - Choosing a router
摘要:We’re going to use the popular third-party package httprouter as the router for our application, instead of using http.ServeMux from the standard-libr
阅读全文
-
Let'sGoFurther - API versioning
摘要:API versioning APIs which support real-world businesses and users often need to change their functionality and endpoints over time — sometimes in a ba
阅读全文
-
VSCode - settings.json
摘要:{ "workbench.startupEditor": "none", "[go]": { "editor.insertSpaces": true, "editor.formatOnSave": false }, "editor.fontSize": 16, "terminal.integrate
阅读全文
-
Let'sGoFurther - Endpoints and Actions of the Greenlight Project
摘要:Method URL Pattern Action GET /v1/healthcheck Show application health and version informationGET /v1/movies Show the details of all moviesPOST /v1/mov
阅读全文
-
Let'sGoFurther - Directory Structure of the Greenlight Project
摘要: mkdir−pbincmd/apiinternalmigrationsremote touch Makefile $ touch cmd/api/main.go At this point your project directory should look exactly li
阅读全文
-
PyTorchStepByStep - Chapter 9: Sequence-to-Sequence
摘要:points, directions = generate_sequences(n=256, seed=13) And then let’s visualize the first five squares: class Encoder(nn.Module): def __init__(self,
阅读全文
-
LaTex - Disable equation auto numbering
摘要:$$ \Large \begin{align} W_{xr} & = {−0.0930,0.0497,0.4670,−0.5319, \\ W_{xz} & = \beg
阅读全文
|