Learn GoLang with VictoriaMetrics ?? | Slices, Maps, and More
VictoriaMetrics
Simple, Reliable, Efficient Monitoring! Metrics & Logs | Open Source & Enterprise | On Premise & Cloud
Welcome to the ??VictoriaMetrics #GoLang Edition Newsletter on LinkedIn. ??
Why is GoLang important for VictoriaMetrics??
VictoriaMetrics is an open-source time-series database (TSDB) written in Go, which our team has had the pleasure of working onfor the past few years. TSDBs have stringent performance requirements, and building VictoriaMetrics has taught us a thing or two about optimization.
Go's cross-platform compatibility ensures our products run smoothly in diverse environments.?
We’re Gophers, enthusiasts who love researching, experimenting, and sharing knowledge about Go and its ecosystem. That's why we’ve started to publish these #GoLang blog posts for ours and the wider Go community. Enjoy this newsletter with a summary of our most recent GoLang user content.?
? Golang Sync Mutex: Normal and Starvation Mode?
Mutex, or MUTual EXclusion, in Go, is a way to ensure that only one goroutine is messing with a shared resource at a time. This resource can be a piece of code, an integer, a map, a struct, a channel, or pretty much anything.
Check out this post. We’re still going from the problem, moving on to the solution, and then diving into how it’s put together under the hood.
Golang Defer: From Basic To Traps ??
Regarding GoLang, the ‘defer’x statement is one of the first features that often catches our attention. While initially seems straightforward, many intricacies and potential pitfalls exist that even experienced developers might overlook.?
We dive deep into how ‘defe’r works, from its primary usage to more advanced topics like the different types of defer in Go 1.22, including open-coded, heap-allocated, and stack-allocated defers. Understanding these nuances can significantly improve performance and help you write more efficient Go code. Let's explore how to defer and avoid common traps.
How Go Arrays Work and Get Tricky with For-Range ??
Golang's arrays and slices might appear simple—arrays with their fixed size and their dynamic nature—but a lot more is happening beneath the surface.?
领英推荐
In this article, we'll start by covering the fundamentals of arrays and then uncover some of the deeper complexities.?
?? Go Maps Explained: How Key-Value Pairs Are Stored?
If you’re new to Go, figuring out how to use maps in Go can be a bit confusing. And even when you’re more experienced, understanding how maps work can be tough. Take this example: Have you ever set a ‘hint’ for a map and wondered why it’s called a ‘hint’ and not something simple like length as we do with slices?
// hint = 10
m := make(map[string]int, 10)
Or maybe you’ve noticed that when you use a for-range loop on a map, the order doesn’t match the insertion order, and it even changes if you loop over the same map at different times. But weirdly enough, if you loop over it simultaneously, the order usually stays the same.
?? Slices in Go: Grow Big or Go Home? ??
? On one hand, new developers often think slices are pretty simple to get—just a dynamic array that can change size compared to a regular array. But honestly, it’s trickier than it seems regarding how they change size.
?? On the other hand, Experienced Go developers think of a slice as a pointer to an array, but here’s the catch ??: that pointer can change without notice, which makes slices tricky if you don’t fully understand how they work. This blog post will cover everything from the basics to how slices grow and allocate them in memory.? ??
Want to learn more about GoLang?
Visit the Go section of our blog to find the latest content on #GoLang.