Go Programming Patterns: Slices, Interfaces, Time, and Performance Go is a high-performance language, but that does not mean we can ignore performance. Here are some tips related to programming and …
Go
All posts
Go Patterns go-design-pattern
15 Rules of Channels and Their Implementation Operation rules Operation nil Closed channel Open buffered channel Open unbuffered channel Close panic panic Close succeeds; buffered values can be read. After …
Pitfalls When Parsing Binary Data in Go for { buf := make([]byte, bufSize) n, err := r.Read(buf) if err == io.EOF { return } else if err != nil { aerr.Store(err) return } ch <- buf[:n] } The code returns …
Take Screenshots with Selenium in Go package main import ( "fmt" log "github.com/sirupsen/logrus" "github.com/tebeka/selenium" "io/ioutil" ) const ( chromeDriverPath = "/usr/local/bin/chromedriver" port = 9515 …
Use Go Fuzzing to Write More Complete Unit Tests func Pow(base uint, exponent uint) uint { if exponent == 0 { return 1 } return base * Pow(base, exponent-1) } func FuzzPow(f *testing.F) { f.Fuzz(func(t …
Go string format Go 语言 fmt.Printf 使用指南 The verb at the end defines the type and the interpretation of its corresponding argument. d - decimal integer o - octal integer O - octal integer with 0o prefix b - …
Build a Lightweight Docker Image for Your Go App? | IT Man go build # default $ go build -o test1 main.go $ du -sh test1 14M test1 # You can add `-ldflags "-s -w"` during compilation to reduce the binary size …
[Golang] Use build tags for different build configs Go build -ldflags package main import ( "fmt" ) var flagString string func main() { fmt.Println("This build with ldflag:", flagString) } $ go build -ldflags …
A Concise Go embed Tutorial Embedding For a single file, you can embed it as string or []byte For multiple files and directories, you can embed them as a new filesystem (FS) Import the “embed” package even if …
Go pprof in Practice Bomb program package main import ( // omitted _ "net/http/pprof" // auto-register handlers to the HTTP server for profiling via HTTP // omitted ) func main() { // omitted …
Go code refactoring : the 23x performance hunt $ go test -bench=. -cpuprofile cpu.prof $ go tool pprof -svg cpu.prof > cpu.svg $ go test -bench=. -trace trace.out $ go tool trace trace.out