Today's Question:  What does your personal desk look like?        GIVE A SHOUT

 GO


  A journey to investigate a goroutine leakage case

In Go, creating goroutines is straightforward, but improper usage may result in a large number of goroutines unable to terminate, leading to resource leakage and memory leaks over time. The key to avoiding goroutine leaks is to manage the lifecycle of goroutines properly. By exporting runtime metrics and utilizing pprof, one can detect and resolve goroutine leakage issues.This post will go through one real case encountered by the author. The author maintains a service that connects to a target machine via SSH and executes commands. This is an internal service that is usually not closely monito...

81 0       GOLANG PPROF GOROUTINE LEAK DEBUG GUIDE SSH TIMEOUT


  Understanding Slice Behavior in Go

In Go, understanding how slices behave when passed to functions is crucial for writing efficient and bug-free code. This behavior is often a source of confusion for many developers, especially those new to the language. In this article, we'll explore the difference between passing slices by value and by reference, and how it impacts the modification of slices within functions.IntroductionIn Go, slices are a fundamental data structure used to work with sequences of elements. They are essentially a view into an underlying array, providing a flexible and powerful way to manipulate collections of ...

100 0       PASS BY REFERENCE ARRAY SLICE PASS BY VALUE


  Connect to SQLite using Go on Windows

In software development, it's often necessary to test and validate logic using a lightweight and easily manageable database system. SQLite, with its minimal setup and zero configuration requirements, is an excellent choice for such scenarios. Leveraging the simplicity and efficiency of SQLite for testing purposes can significantly streamline the development process. In this guide, we'll explore how to seamlessly connect to SQLite using Go on Windows, empowering developers to efficiently test their code with a reliable and straightforward database solution.Install SQLIte3 PackagesGo has built-i...

341 0       WINDOWS TUTORIAL GOLANG SQLITE3


  Break down defer statements in GoLang

Basic ConceptsWhat are the characteristics of the deferred statement defer in Go language? When is it usually used?The deferred statement(defer statement) in Go language has the following characteristics:Deferred Execution: Deferred statements are executed before the function containing them exits, regardless of whether the function returns normally or encounters an exception.Last In, First Out (LIFO): If there are multiple deferred statements, they are executed in the order of last in, first out (LIFO). In other words, the last deferred statement is executed first, and the first deferred stat...

599 0       DEFER GOLANG


  Rust vs Go: how to choose the best programming language for your project?

Rust and Go, these two modern programming languages, with their unique advantages, are becoming hot topics in the developer community. Their competition in performance, security, simplicity, feature set, and concurrency not only influences developers' choices but also foretells future trends in software development.Battle of Performance: Rust's Precision vs. Go's EfficiencyRust, developed by Mozilla Research, has become the preferred choice for performance-sensitive applications due to its zero-cost abstractions and memory safety features. It ensures memory safety through concepts like ownersh...

1,150 0       COMPARISON GO GOLANG RUST


  What is goroutine?

Casual TalkGolang is quite enjoyable to write, aside from the tedious if err != nil checks. One of the fundamental reasons for the joy is goroutine, a core feature of Golang. Understanding goroutines in detail is worthwhile, as they contribute significantly to the pleasure of working with Golang. So, let's talk about goroutines, hoping to provide some insights to the readers.TL;DR: We'll start by talking about assembling a computer, then delve into some concepts of the operating system, such as processes and threads, before exploring goroutines themselves.Assembling a ComputerLet's focus on de...

743 0       EXPLANATION GOLANG GOROUTINE


  Deep Dive into Spin Locks in Golang

In concurrent programming, a Mutex is a commonly used synchronization mechanism to protect critical resources and prevent data races. However, in certain specific scenarios, especially when the lock-holding time is short and the number of threads is limited, a more lightweight lock known as a Spin Lock can provide higher performance.What is a Spin LockA Spin Lock is a form of busy-wait lock. When a thread attempts to acquire a lock held by another thread, it continuously checks the lock's status (i.e., "spins") until the lock is released, at which point it takes ownership. This waiting method ...

671 0       GOLANG MUTEX SPINLOCK


  How to Understand and Use nil in Golang Correctly?

In Golang, nil is a predefined identifier that carries different meanings in various contexts, but typically represents "none", "empty" or "zero value". It can be assigned to variables of pointer, slice, map, channel, function, and interface types. Understanding the significance of nil is crucial for writing robust Go programs, as mishandling nil can lead to unexpected issues.nil in PointersIn Go, pointers are a fundamental type that stores the memory address of a variable. When a pointer is declared but not initialized, its value is nil. The following example code illustrates this:package mai...

975 0       NIL GOLANG CHANNEL MAP SLICE FUNCTION