Articles by Tuan Nguyen
Compare Structs, Slices, and Maps in Go (Equality and Deep Equality)
Learn how to compare two structs, slices, and maps in Go: struct equality with ==, slice and map checks with slices.Equal and maps.Equal (Go 1.21+), reflect.DeepEqual, test-focused go-cmp, and when to write your own …
Copy Structs in Go: Value Assignment, Pointers, Shallow vs Deep
Copy structs in Go: assignment copies the struct value; fields that are slices, maps, or pointers still alias shared backing data unless you duplicate them; primitives and arrays inside the struct copy by value.
Golang UDP server and client: ListenPacket, DialUDP, and sending packets
Golang udp server and udp server golang with net.ListenPacket, golang udp client and go udp server patterns with DialUDP, golang send udp packet via WriteTo and Write, plus a minimal udp example for go udp and golang udp …
Golang TCP server and client: step-by-step from basic to advanced
Step-by-step golang tcp server and golang tcp client: net.Listen and net.Dial, tcp server golang and tcp client golang patterns, deadlines and concurrent accepts with the net package.
Golang Struct Embedding: Composition, Promoted Fields, and Methods
Golang struct embedding and go struct embedding: anonymous embedded fields, promoted fields and methods per the Go spec, composition vs inheritance, pointer embedding, name conflicts, interface embedding, satisfying …
Golang SHA-512: Sum512, hex, files, streams, salt verify, and SHA-256 comparison
Golang SHA-512 with crypto/sha512: Sum512 and hex, sha512.New streaming io.Copy, file checksum verify, streams vs one-shot, salt-and-hash demo with verification caveats, SHA-512 vs SHA-256, HMAC, use cases, passwords …
Golang Compare Strings: Equality, Ordering, and Case-Insensitive Match
Compare strings in Go with == and !=, lexicographic order with < and >, strings.EqualFold for case-insensitive match, strings.Compare for three-way results, and trimming input before comparing.
Golang Command Line Arguments: os.Args, Flags, and Examples
Read command-line arguments in Go with os.Args, use the flag package for named options, validate positional args, parse numbers safely, and understand go run vs a compiled binary.
What Is Ampersand in Golang? & and * Pointer Operators Explained
Learn what ampersand means in Go, how & gets a variable address, how * works with pointers, and how & and * are used together in simple examples.
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 SHA-256: Sum256, hex, files, streams, verification, and security notes
Golang SHA-256 with crypto/sha256: Sum256 and hex, sha256.New streaming io.Copy, file checksums and verification, compare files, subtle comparison, HMAC sign/verify, MD5 vs SHA-1 vs SHA-256, passwords use bcrypt; quick …
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 byte to int and []byte to int: strconv, binary, big.Int
Golang byte to int: uint8 widening, []byte ASCII to int with strconv.Atoi and validated ParseInt, math/big SetBytes for long unsigned magnitudes, encoding/binary Uint32 Uint64 and Read for int32, reverse int64 to []byte …
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 Read YAML File: Parse YAML into Struct, Map, or Decoder
Learn how to read and parse YAML files in Go using gopkg.in/yaml.v3: YAML to struct, YAML to map, nested YAML, lists, os.ReadFile, yaml.NewDecoder, multi-document YAML, KnownFields for strict keys, scalar pitfalls, and …
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.

