programming

GraphQL in Go: golang graphql tutorial, examples, and HTTP server

Graphql golang tutorial and golang graphql example with github.com/graphql-go/graphql: schema, resolvers, graphql.Do, context, HTTP handler and Playground, go graphql patterns, graphql golang vs REST, and graphql mongodb …

Tuan Nguyen6 min read
programming

Golang break and continue: inner loop, outer loop, and select

Golang break and golang continue for go break loop and golang break for loop; golang break outer loop and golang continue outer loop with labels; golang select break exits the select—use a label to leave the surrounding …

Antony Shikubu4 min read
programming

Golang Fiber CRUD API tutorial: routes, JSON, and Postman

Go fiber tutorial and golang fiber CRUD REST demo: fiber golang routing, fiber routes API with grouped paths, JSON handlers with Fiber, in-memory articles, Postman screenshots—practical codebase for fiber go and fiber …

Antony Shikubu12 min read
programming

Golang FIFO and named pipes: mkfifo, syscall.Mkfifo, EOF, open modes

Golang fifo and golang mkfifo: create fifo files with syscall.Mkfifo or mkfifo command in linux, golang named pipe reader and writer, O_RDONLY vs O_RDWR and EOF handling—linux fifo example and go fifo inter-process …

Antony Shikubu4 min read
programming

Golang bool to string: FormatBool, Sprintf, and string to bool

Golang bool to string and bool to string golang: strconv.FormatBool for golang convert bool to string, golang sprintf bool with fmt.Sprintf %t or %v, golang string to bool with strconv.ParseBool, go bool to string …

Tuan Nguyen3 min read
programming

Golang base64 encode and decode with encoding/base64 and JSON

Golang base64 and base64 golang: StdEncoding EncodeToString DecodeString, URLEncoding, padding; golang base64 decode and base64 decode golang; golang json prevent encoding byte to base64 when json.Marshal treats []byte …

Deepak Prasad4 min read
programming

Golang sort slice and array: Ints, Slice, SliceStable, descending

Golang sort slice and go sort slice: sort.Ints, sort.Strings, golang sort array with a slice view, sort.Slice and sort.SliceStable, golang sort descending and reverse slice golang, sort.Sort with IntSlice and …

Tuan Nguyen5 min read
programming

Golang Run Function at Intervals: Ticker, Sleep, and Cron Examples

Run repeated tasks in Go with time.NewTicker and time.Sleep, stop loops with context, avoid overlapping runs, and use robfig/cron/v3 for wall-clock schedules.

Tuan Nguyen6 min read
programming

Golang escape backslash and escape string: raw literals vs "quoted"

Golang escape string and go escape string: golang escape backslash with doubled backslash in double-quoted strings, golang escape characters in interpreted literals, raw string literals for paths, and golang escape …

Deepak Prasad4 min read
programming

Golang array of structs and slice of structs: declare, init, iterate

Golang array of structs and golang struct array: [n]T fixed array vs []T slice, golang initialize array of structs with literals or loops, golang make array of structs with make, golang list of structs and go array of …

Deepak Prasad4 min read
programming

Go environment variables: getenv, setenv, lookup, go env, and .env files

Go environment variables and golang environment variables: golang get environment variable with LookupEnv, golang set environment variable with Setenv, go env vs process env (golang env, go env variables), env golang and …

Antony Shikubu6 min read
programming

Golang const array: why Go has no constant slices, and what to do instead

Golang const array and golang constant array: Go constants are only numbers, strings, booleans, and complex values built from those—no golang constant slice or const array type; patterns for golang const string array, go …

Tuan Nguyen5 min read
programming

GOPATH vs GOROOT: what is GOROOT, go root, and how they differ

Gopath vs goroot and goroot vs gopath: what is goroot (go root / golang goroot), GOPATH for your workspace, why GOPATH and GOROOT must not be the same directory, go env GOROOT and go env GOPATH, modules and GOMODCACHE, …

Tuan Nguyen5 min read
programming

Golang sed and awk examples from Go with os/exec

Golang sed and go sed: call sed and awk from Go with os/exec, stdin pipes, temp files, and notes on in-place edits and golang execute shell command patterns.

Deepak Prasad5 min read
programming

Golang new error: errors.New, fmt.Errorf, and custom errors

Golang new error and golang create error with errors.New and fmt.Errorf; errors new golang patterns, sentinels, errors.Is, %w wrapping, and custom types implementing error.

Tuan Nguyen4 min read
programming

Remove or Delete Elements from a Slice in Go (First, Last, by Index)

Remove the first or last element from a slice in Go, delete by index while keeping order or in O(1) with swap-and-truncate, drop a run of elements, and use slices.Delete on Go 1.21+.

Deepak Prasad5 min read
programming

Golang append to slice: elements, another slice, and []byte rules

Golang append and append golang: golang add to slice, golang append to slice and golang slice append with variadic ..., golang append slice to slice, go append to array semantics, []byte plus string append, and always …

Tuan Nguyen4 min read
programming

Golang cast to string: int, any, and bool with strconv and fmt

Golang cast to string and go cast to string: golang int to string and convert int to string golang with strconv and fmt; golang convert any to string and golang cast any to string with type switches and fmt.Sprint; bool …

Deepak Prasad3 min read
programming

Golang init function: syntax, rules, and order of execution

Golang init and go init: func init() rules, init order across imports and files, multiple init functions, blank imports, when to use or avoid init(), with spec-aligned examples.

Tuan Nguyen6 min read
programming

Access a Go variable from another package: exports, imports, and globals

Golang global variables across packages: package-level vars with an exported name (capital letter), import path module/subpkg, golang declare global variable in util and read from main; why main cannot be imported and …

Deepak Prasad4 min read
programming

Golang read file into string or variable: os.ReadFile, embed, Open

Golang read file into string and read file golang: os.ReadFile for golang read file to string, go read file to string and []byte, //go:embed for build-time content, os.Open with io.ReadAll; notes for golang read from …

Deepak Prasad4 min read
programming

Golang prompt for input: interactive CLI with bufio and fmt

Golang prompt for input and go interactive cli: read lines from stdin with bufio for a go prompt, yes/no prompts, Scanln loops, and validation with strconv; note c-bata go-prompt library vs stdlib for golang prompt and …

Tuan Nguyen5 min read
programming

Go get specific version and go get version with Go modules

Go get specific version and go get version with modules: go get with version and go get package version using @v1.2.3, go list for go get version of package, go update package to specific version with @latest and …

Tuan Nguyen5 min read
programming

Go map to struct: convert map[string]any and round-trip with structs

Golang map to struct and golang convert map to struct: map[string]any (map string interface) to struct via json.Marshal or mapstructure, manual loops, reflect; plus convert struct to map golang with JSON for map to …

Deepak Prasad6 min read
programming

Go const map and constant map: Why They Are Not Allowed and What to Use Instead

Go does not allow golang const map or golang map const literals: constants must be compile-time values of allowed types. Use a golang global map with var and init, getters over unexported maps, or functions that return …

Deepak Prasad5 min read
programming

Golang mutex: sync.Mutex lock and unlock with examples

Mutex in golang with sync.Mutex: Lock and Unlock, fix data races with go run -race, golang mutex lock patterns, defer unlock, sync.RWMutex for many readers, embed a mutex in a struct.

Antony Shikubu5 min read
programming

Golang global variables: package scope, exports, structs, and pitfalls

Golang global variable and golang global variables: package-level var, global variable declaration golang, golang globals and go global variables, golang global variables across packages with exported names, global …

Antony Shikubu6 min read
programming

Go map to JSON: convert, print, and parse back with encoding/json

Golang map to JSON and JSON string: json.Marshal and string(bytes) to convert map to json golang, MarshalIndent and Encoder to print map as JSON, then json.Unmarshal for json to map golang (map[string]any) with …

Deepak Prasad4 min read
programming

Gorilla mux in Go: routing, path variables, subrouters, and middleware

Gorilla mux tutorial for gorilla mux and golang gorilla mux: install github.com/gorilla/mux, gorilla mux example with Methods and path vars, subrouters, middleware with r.Use, mux gorilla naming, and gorilla mux vs gin …

Antony Shikubu3 min read
programming

Go comma ok idiom: map, type assertion, and channel receive

Golang comma ok idiom and go comma ok idiom: the second bool from v, ok := m[k], v, ok := x.(T), or v, ok := <-ch; comma ok idiom golang covers maps, type assertions, and closed channels—not the same as if err != nil.

Antony Shikubu4 min read