Articles by Tuan Nguyen
Golang Time Format: Format, Parse, and Layout Examples
Learn Go time formatting and parsing with the reference date 2006-01-02, RFC3339, DateOnly, time.Format, time.Parse, ParseInLocation, and timezone layouts.
Golang Time Package: time.Now, Duration, Parse, and Date Examples
Learn Go's time package with examples for time.Now, UTC, Duration, Add and Sub, Unix timestamps, time zones, Format, Parse, Sleep, Timer, and Ticker.
Convert String to uint8 or byte in Go
Convert a Go string to uint8 using strconv.ParseUint, validate the 0–255 range, and learn the difference between parsing numeric text and reading a string byte.
Import a Struct from Another File or Package in Go
Learn how to use a Go struct defined in another file, import an exported struct from another package, and fix undefined errors caused by go run main.go.
Convert int to int64 and int64 to int in Go
Convert int to int64 and int64 to int in Go, understand 32-bit vs 64-bit int sizes, check values before narrowing, and choose the correct integer type.
Golang Kill Process by PID: Kill, Signal, and CommandContext
Learn how to kill a process by PID in Go, stop exec.Command children, use Process.Signal vs Kill, handle timeouts with CommandContext, and avoid orphan processes.
Golang `io.ReadCloser`: Read, Close, `NopCloser`, and Convert to String
Learn how io.ReadCloser combines Reader and Closer in Go, how to close HTTP response bodies, wrap readers with io.NopCloser, and read content with io.ReadAll.
Fix Go "package is not in GOROOT" and "cannot find package"
Fix Go "package is not in GOROOT", "cannot find package", and missing module errors by checking go.mod, import paths, workspaces, dependencies, and GOPATH mode.
Golang SHA-256: Hash Strings, Files, and Verify Checksums
Use Go crypto/sha256 to hash strings and files, format SHA-256 as hexadecimal, stream large files with io.Copy, and verify known checksums.
Golang byte to int: Convert `byte` and `[]byte` Correctly
Convert byte and []byte to integers in Go using int, strconv.Atoi, encoding/binary, varints, and big.Int, with byte order and error handling explained.
Golang JSON `omitempty`: Zero Values, `omitzero`, and Nested Structs
Learn how Go JSON omitempty works for zero values, pointers, slices and nested structs, how omitzero differs, and what changes with encoding/json/v2 in Go 1.27.
Convert float64 to int or int64 in Go
Convert float64 to int or int64 in Go using direct conversion or math.Round, RoundToEven, Floor and Ceil, with overflow, NaN and Inf handling.
How to Remove or Uninstall a Go Package
Learn how to remove a Go module dependency, undo go get, remove Go 1.24+ tool dependencies, uninstall go install binaries, and clear the module cache.
Golang os.Stat: File Metadata, File Existence, and Lstat
Learn how to use os.Stat in Go to read file metadata, check whether a path exists, distinguish files and directories, handle errors, and compare Stat with Lstat.
Go Gopher: History of the Golang Mascot
Learn who created the Go Gopher, how Renée French's WFMU character became Go's mascot in 2009, whether it has a name, and how the artwork is licensed.
Fix "go.mod file not found in current directory or any parent directory"
Fix Go's "go.mod file not found in current directory or any parent directory" error for existing projects, new modules, go get, workspaces, IDEs, and CI.
Golang os Package: Files, Directories, and Environment Examples
Learn the Go os package with practical examples for opening, creating and writing files, working with directories, file metadata, environment variables, and paths.
Fix Go "declared and not used" and "imported and not used"
Fix Go's "declared and not used" and "imported and not used" compiler errors, including blank identifiers, unused return values, imports, and := shadowing.
Golang WebSocket Examples: Server and Client
Learn how to build a WebSocket server and client in Go using Gorilla WebSocket, send text and JSON messages, close connections, and handle common errors.
Golang Read YAML File: Parse YAML into Struct or Map
Learn how to read and parse YAML files in Go, unmarshal YAML into structs or maps, handle nested data and lists, and decode multiple YAML documents.
Golang Cobra Tutorial: Subcommands, Flags, and CLI Examples
Golang Cobra tutorial with a complete go cobra example: install spf13/cobra, build subcommands, local and persistent flags, test with go run, set --version, and scaffold apps with cobra-cli.
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.

