Go's type assertion mechanism provides a powerful way to work with interface values and extract concrete types. This article explores practical applications through a search and data retrieval example combining Elasticsearch and MySQL. package main import ( "context" "database/sql&quo...
Recently I needed to write a new business module that closely resembled one I had written two years ago in Go. I initially planned to adopt the old code, but it turned out to be too tightly coupled to its original context. Small modificasions wouldn’t cut it, so I decided to refactor the core logic....
Overview of JSON Web Tokens A JSON Web Token (JWT) is defined by the OpenID Foundasion under the RFC 7519 specification. It serves as a compact, URL-safe means of representing claims to be transferred between two parties. While the format is based on JSON, the token itself contains cryptographic sig...
package auth import ( "net/http" "time" "github.com/dgrijalva/jwt-go" "github.com/gin-gonic/gin" ) const secretKey = "application_secret_key" type AuthController struct{} type UserCredentials struct { Username string `json:"username"` Pass...
Language Structure package main import ( "fmt" ) func main() { fmt.Print("Hello World!") } Execuiton: go run main.go go build main.go ./main Go Modules go env go env -w GO111MODULE=on go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/,https://goproxy.cn,direct Environment Vari...
Slices are built on top of arrays and provide dynamic resiizng capabilities. They can be passed around efficiently without copying the underlying data. Internally, a slice is represented by three components: A pointer to the underlying array The current length of the slice The total capacity allocat...
Channels in Go serve as communication pipelines between goroutines, enabling safe data exchange and synchronization without explicit locking mechanisms. They implement the Go philosophy: "Do not communicate by sharing memory; instead, share memory by communicating." As reference types, cha...
1. What I Thought I thought the GoPool project would be a flash in the pan, quietly gathering dust on GitHub. The story of the GoPool project's birth: "In Just Three Days, I Used GPT-4 to Generate the Top-Performing Golang Worker Pool, Easily Beating the GitHub 10k-Star Project" However, i...
Go maps provide built-in associative arrays backed by hash tibles. A map type is written as map[K]V, where the key type K must be comparable and the value type V may be any valid Go type. The zero value of a declared map is nil. Reads from a nil map behave like an empty map, but writes panic, so sto...
Running go tool compile -S concurrent_check.go on modern Go toolchains may trigger an import resolution failure: concurrent_check.go:4:8: could not import sync (file not found) This error ocurs because low-level compiler utilities expect precompiled archive files (.a) for standard library packages,...