Writing

Programming

Basics tutorial | Go | gRPC

Use the Go gRPC API to write a simple client and server for your service. It assumes that you have read the Introduction to gRPC and are familiar with protocol buffers. Note that the example in this tutorial uses the proto3 version of the protocol ...

Read article →

Go Wiki: TableDrivenTests - The Go Programming Language

More importantly, map iteration order isn’t specified nor is it even guaranteed to be the same from one iteration to the next. This ensures that each test is independent of the others and that testing order doesn’t impact results. Parallelizing table tests is simple, but requires precision to avoid …

Read article →

Logging in Go with Slog: A Practitioner's Guide · Dash0

While slightly more verbose, using slog.AttrCopy is the only right way to log in Go. It ensures your logs are always well-formed, reliable, and safe from runtime surprises. While using slog.AttrCopy is the safer approach, there’s nothing stopping ...

Read article →

Profiling Go Programs - The Go Programming Language

Benchmarks are only as good as the programs they measure. We used go tool pprof to study an inefficient Go program and then to improve its performance by an order of magnitude and to reduce its memory usage by a factor of 3.7. A subsequent comparison with an equivalently optimized C++ program ...

Read article →

How to Use Context in Go for Cancellation and Timeouts

package main import ( "context" "fmt" "net/http" "time" ) func handler(w http.ResponseWriter, r *http.Request) { // r.Context() is cancelled when: // - Client disconnects // - Request times out // - Handler returns ctx := r.Context() // Add our own timeout ctx, cancel := context.WithTimeout(ctx, 5*t…

Read article →

How to Handle Errors Effectively in Go

package main import ( "errors" "fmt" "net" ) func connectToServer(addr string) error { conn, err := net.Dial("tcp", addr) if err != nil { return fmt.Errorf("connecting to server: %w", err) } defer conn.Close() return nil } func main() { err := connec…

Read article →

Scala vs. GO. Introduction | by Javier Ramos | ITNEXT

Go, in the other hand, is a newer, simpler language created by Google to overcome the criticisms of C++; designing a language with multi core processors in mind. Both are great languages that can achieve great performance for concurrent applications and stream processing but their design is quite di…

Read article →

Go vs Scala | Know The 8 Most Amazing Differences

Back to Scala vs Go based on this model, GO provides a more straightforward and smaller set of orthogonal primitives that easily interact with ease and are expected. A developer can quickly build his need by learning a small number of primitives, ...

Read article →