Articles by Tuan Nguyen
Go Import Underscore Explained: Blank Imports and Side Effects
Learn why Go uses underscore before an import path, how blank imports work, when packages are imported for side effects, and how this relates to unused import errors.
Import Local Package in Go Without GOPATH: Step-by-Step Go Modules Example
Learn how to import a local Go package without GOPATH using go.mod, module paths, subfolders, exported names, replace directives, and go.work.
Golang Slice Contains and Find Index: Contains, Index, and IndexFunc
Learn how to check if a Go slice contains a value, find the index of an element, search by condition with IndexFunc, and choose between slices, loops, and maps.
Golang Anonymous Struct: Inline Structs, JSON, Methods, and Return Values
Learn anonymous structs in Go: inline struct syntax, JSON tags, slices and maps, returning unnamed struct types, why methods attach to named types, embedding vs anonymous fields, and when to use a named struct.
Golang import local package: modules, paths, and another directory
Golang import local package and go import local package with Go modules: golang import package from another directory under the module root, golang use local package and golang local package import paths, golang import …
Best Go Web Frameworks: Gin, Echo, Fiber, Chi, and net/http Compared
Compare popular Go web frameworks including Gin, Echo, Fiber, Chi, Beego, and net/http. Learn which framework fits REST APIs, microservices, web apps, and high-performance services.
Golang HTTP and HTTPS servers with net/http and ListenAndServeTLS
Golang http and go http with net/http: golang http server example using ListenAndServe and ServeMux, golang https server and https golang with http.ListenAndServeTLS, golang http module meaning the standard library …
Golang Handle Ctrl+C: Catch SIGINT and Run Cleanup Before Exit
Learn how to catch Ctrl+C in Go with os/signal, handle SIGINT and SIGTERM, run cleanup before exit, choose between signal.Notify and signal.NotifyContext, and how Docker and PID 1 differ from a normal terminal.
Golang multiply duration by integer: int to time.Duration
Golang multiply time duration and fix mismatched types int and time.Duration; golang int to time.Duration with time.Duration(n)*time.Second; constants; golang time duration example; max int64 nanoseconds overflow.
Golang multiline string: raw literals, concatenation, and variables
Golang multiline string and go multiline string: raw string literals in backticks, golang multiline string literal rules, concatenation with \\n, golang multiline string with variables via fmt and strings.Builder.
Golang Ticker Example: Run Code Repeatedly with time.NewTicker
Use time.NewTicker in Go for repeated work at a fixed interval: ticker.C, Stop, Reset, select with done or context, goroutine patterns, timer vs ticker, time.Tick pitfalls, and common mistakes.
Golang HTTP client timeout and server timeouts with a test server
Golang http client timeout and go http client timeout: http.Client zero means no timeout per pkg.go.dev, Transport dial TLS ResponseHeaderTimeout, context request deadline, golang http timeout vs golang http request …
Golang Subtract Time: time.Now Minus Duration Examples
Subtract time in Go with time.Add and negative durations, time.Now minus 1 hour, time.Sub for differences between two time.Time values, AddDate for calendar days and months, and common mistakes.
Golang Function as Parameter Explained with Examples
Pass functions as parameters in Go: func types, named and anonymous arguments, callbacks, defined function types, method values and expressions, errors, and when to prefer an interface or generics.
Go get private repository: GOPRIVATE, SSH, HTTPS, and go mod private repo
Go get private repository and golang private repo with modules: GOPRIVATE, GONOPROXY, GONOSUMDB, SSH insteadOf HTTPS, PAT and .netrc, go no secure protocol found for repository, terminal prompts disabled, GitHub GitLab …
Golang MongoDB tutorial: driver v2, BSON, ObjectId, and CRUD
Step-by-step golang and mongodb with go.mongodb.org/mongo-driver/v2: URI connect Ping, implicit create database, BSON golang bson ObjectId, CRUD, bson regex golang, dates; legacy mgo note.
Encrypt and decrypt strings in Go with AES-GCM
Encrypt and decrypt byte slices or strings in Go using AES-256 with GCM for confidentiality and integrity, a random nonce per message, and base64 for storage; extend the same pattern to files by reading and writing raw …
Golang lint and go vet: golangci-lint, formatting, and nolint:gosec
Golang linting with go vet and golangci-lint; go lint command meaning versus go vet; golang linter setup; nolint:gosec and targeted nolint directives; gofmt goimports; golint deprecated.
Golang URL query parameters: url.Values, encoding, and reading requests
Golang url values and url.Values.Encode to add query parameters; golang http request parameters from r.URL.Query; golang url parameters with Set and Add; avoid raw fmt.Sprintf for untrusted strings. Related HTTP overview …
Golang HTTP POST JSON: send a post request with a JSON body in Go
Golang http post json and golang post request with json body using net/http: http.NewRequest with bytes.Reader, Content-Type application/json, json.Marshal, and a minimal server decode with json.Decoder; httptest example …
Golang performance and speed: how Go compares and why it is fast
Golang performance versus Java, Python, Node.js, and C; why the Go language feels fast for servers; golang performance benchmark with go test; golang closure performance basics; links to official docs and community …
Go pass by value or reference: pointers, slices, and maps in Go
Is go pass by value or reference: Go passes arguments by value; golang pass by reference means passing pointers. go pass by value for structs; slices and maps alias shared data. golang pass by reference or value, golang …
Golang print struct: fmt verbs, pretty JSON, and type names
Print struct golang and go print struct with fmt.Printf verbs (%v %+v %#v), golang pretty print struct via encoding/json, golang print type of variable with %T and reflect.TypeOf, fmt.Stringer, and optional go-spew.
Golang queue: FIFO slice, container/list, and channels
Golang queue implementation for FIFO: slice append and reslice, golang fifo queue memory notes, container/list, buffered channel go queue, generics helpers, peek and empty checks, concurrency hints, and links to channels …
Golang prompt and interactive CLI: stdin, passwords, promptui, survey
Golang interactive CLI and golang prompt for input with bufio; golang.org/x/term ReadPassword with os.Stdin.Fd; promptui golang and survey; go-prompt (c-bata); notes on TTYs and cross-platform terminals.
Golang read file, update in place, and overwrite safely
Golang read file and golang read entire file with os.ReadFile; golang open file and os.OpenFile flags; golang overwrite file and append; update one field of big file golang via temp file rename or streaming; WriteAt …
Golang multiline string and reading multiple lines from stdin
Golang multiline string with raw backticks and escapes; golang read stdin and golang read line from stdin using fmt.Scan tokens, bufio.Reader ReadString, and bufio.Scanner; EOF and token size notes; not golang multiline …
Golang random bool and random boolean: math/rand and crypto/rand
Golang random bool and golang random boolean with math/rand Intn and Float64, golang rand local source for tests, random boolean generator patterns in Go, and crypto/rand when you need unpredictable bits—not Python or …
Delete keys from a map in Go with delete()
Remove entries from a map in Go with the built-in delete(map, key); deleting a missing key is safe; use the comma-ok form first when you want to log or branch on absent keys.
Golang print type: %T, reflect, and type switches
Go print type and golang print type of variable with fmt %T; golang get type via reflect.TypeOf and Kind; pointers, interface{}, and nil; type switches; golang print object as dynamic concrete type.

