programming

Golang Regexp Tutorial: Match, Find, Replace, and Extract Regex Groups

Learn how to use regex in Go with the regexp package, including MatchString, Compile, MustCompile, FindString, submatches, ReplaceAllString, Split, and common mistakes.

Deepak Prasad9 min read
programming

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.

Tuan Nguyen16 min read
programming

Goroutine vs Thread in Go: Are Goroutines the Same as Threads?

Understand the difference between goroutines and OS threads in Go, how the Go runtime scheduler maps goroutines onto threads, and why goroutines are lightweight.

Deepak Prasad10 min read
programming

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.

Tuan Nguyen8 min read
programming

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 …

Tuan Nguyen4 min read
programming

Golang functions: syntax, parameters, returns, methods, closures, and defer

Golang function guide: overview, syntax and naming, declaring and calling, single and multiple returns, errors and pointers, pass by value vs pointer, struct map slice channel, variadic pointer to variadic article, …

Antony Shikubu12 min read
programming

Golang Fan-Out Fan-In Pattern: Goroutines, Channels, and Worker Pools

Learn the fan-out fan-in pattern in Go with goroutines and channels: distribute work, merge results, relate it to worker pools, handle errors and cancellation, preserve ordering when needed, and close channels safely.

Antony Shikubu12 min read
programming

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.

Tuan Nguyen9 min read
programming

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 …

Tuan Nguyen5 min read
programming

Golang portping: TCP checks with Ping and PingN (sequential, parallel, ranges)

Golang portping with janosgyerik/portping: set up module, Ping and PingN API, sequential and parallel TCP checks, port ranges, PingN result handling, retries, per-dial timing, CLI install, common dial errors; links to …

Deepak Prasad9 min read
programming

Golang Trim String: Remove Whitespace, Prefix, and Suffix

Trim strings in Go with strings.TrimSpace, strings.Trim, TrimPrefix, and TrimSuffix to remove whitespace, cutset characters, and exact prefixes or suffixes.

Antony Shikubu7 min read
programming

Golang store values in a struct using a for loop

Store slice values into structs with for range, golang iterate over struct fields with reflect, and a short golang forloop refresher—correct Go, no broken examples.

Deepak Prasad3 min read
programming

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.

Tuan Nguyen8 min read
programming

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.

Tuan Nguyen3 min read
programming

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.

Tuan Nguyen3 min read
programming

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.

Tuan Nguyen8 min read
programming

Golang background process: start, monitor, and wait with os/exec

Golang start process and spawn with os/exec Start Wait and Run; CommandContext timeouts; goroutines channels WaitGroup for golang background jobs; go run in background vs shell; wait golang patterns.

Deepak Prasad5 min read
programming

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 …

Tuan Nguyen6 min read
programming

Golang Check If String Is Empty: Empty vs Blank String

Check if a string is empty in Go with s == "" or len(s) == 0, tell empty from whitespace-only strings, use strings.TrimSpace for blank input, and remember string is never nil.

Azka Iftikhar6 min read
programming

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.

Tuan Nguyen9 min read
programming

Golang Switch Case Statement: Examples, Multiple Cases, and Type Switch

Use the switch statement in Go for switch case and default, comma-separated cases, expressionless switch, initial statements, type switch on any, fallthrough, and patterns that replace long if-else chains.

Deepak Prasad10 min read
programming

Find GCD in JavaScript (Euclidean algorithm, BigInt, mathjs)

GCD in JavaScript (greatest common divisor, not denominator): Euclidean gcd recursive and iterative with Math.abs for negatives, reduce fold for many numbers, BigInt gcd without mixing Number, optional mathjs variadic …

Olorunfemi Akinlua5 min read
programming

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.

Tuan Nguyen8 min read
programming

Install Go on Ubuntu: apt, snap, or official tarball (with checksum)

Installing golang on Ubuntu: apt golang-go, snap install go --classic, official go.dev/dl tarball with sha256 verify, optional build-from-source with bootstrap Go, amd64 and arm64, PATH and GOBIN, go version, go mod init …

Deepak Prasad8 min read
programming

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 …

Tuan Nguyen5 min read
programming

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.

Tuan Nguyen6 min read
programming

Golang methods: receivers, struct methods, and interfaces

Golang method and go methods: value vs pointer receivers, golang struct methods and calls, methods on defined types, method sets and interfaces; same-package rules and when Go adjusts & for you.

Antony Shikubu5 min read
programming

Enums in Go with iota, named types, and String()

Model a golang enum as a named integer type with const iota values, optional String and fmt.Stringer, validation helpers, and JSON encode or decode via maps or custom MarshalJSON when strings cross APIs.

Antony Shikubu2 min read
programming

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 …

Tuan Nguyen3 min read
programming

Smaller Go Docker images with multi-stage builds

Shrink a Go service image with Docker multi-stage builds: compile in a golang image, then copy only the static binary into a minimal runtime such as Alpine so the final image stays small for deploy and bandwidth.

Antony Shikubu3 min read