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

 GO


  Learning Go

This year I'm going to try a new programming language - Go. I had this notion that compiled, type based languages are overly complex and reduces developer efficiency. However, after doing some reading about Go, it appeared to take a different path from the rest and felt like something worth trying.Acquainting a programming language is a journey. First few steps you take with it will define your perception about it. These first few steps went well for me with Go and it felt like a good fit for my repertoire. I thought of sharing my learning experience, hoping it will help others who w...

2,270 0       GO GOOGLE LEARNING RESOURCE


  Understand GoLang WaitGroup internals and how it works

BackgroundBefore getting into the main content, let me give a brief introduction to WaitGroup and its related background knowledge. Here, the focus is on the basic usage of WaitGroup and the fundamental knowledge of system semaphores. For those who are familiar with these, you can skip this section directly.WaitGroupWaitGroup is one of the most common concurrency control techniques in Golang, and its function can be roughly compared to the join() in concurrency control of other languages' multithreading. The sample code is as follows:package mainimport ( "fmt" "sync" "time")func main(...

2,238 0       SOURCE CODE GOLANG WAITGROUP


  Publish Your Go Package on pkg.go.dev

go.dev is a site where various resources for Go developers are shared, such as “Get Started”, Tutorial, Packages (pkg.go.dev), and all the official blogs. Among them, Packages is where I visit most, which allows free access to all the open-source Go packages submitted by communities including the native Golang packages. Thanks to all the contributors, I enjoy the great benefit, and sometimes I want to be a contributor myself.Let’s submit a “complete” package to pkg.go.dev today.Came pkg.go.dev into beingBefore pkg.go.dev’s birth...

2,147 0       GOLANG PUBLISH PACKAGE GO.DEV


  How the Go language improves expressiveness without sacrificing runtime performance

This week there was a discussion on the golang-nuts mailing list about an idiomatic way to update a slice of structs. For example, consider this struct representing a set of counters. type E struct { A, B, C, D int}var e = make([]E, 1000)Updating these counters may take the form for i := range e { e[i].A += 1 e[i].B += 2 e[i].C += 3 e[i].D += 4}Which is good idiomatic Go code. It's pretty fast too BenchmarkManual 500000 4642 ns/opHowever there is a problem with this example. Each access the ith element of e requires the compiler to insert an...

2,101 0       GO EXPRESSIVENESS PERFORMACE SACRIFICE


  How to check when an API is introduced in GoLang

Normally people would not pay much attention to which GoLang version is being used as lots of functions are backward compatible. However there are cases where GoLang version does matter as some functions may not be supported by old version of GoLang. For example, strings.Builder is introduced in Go 1.10, but below code would fail to be compiled on Go 1.10.package mainimport ( "fmt" "strings")func main() { var b strings.Builder b.WriteString("polarisxu") fmt.Println(b.Cap())}The compilation error is:$ go versiongo version go1.10.8 darwin/amd64$ go run main.go# command-line-arguments./main.g...

2,004 0       GO TOOL API VERSION GOLANG


  Singleton Pattern in Golang

Singleton pattern is the simplest design pattern in software design. It ensures that only one instance of an object exists globally, regardless of how many times the object is instantiated. Based on the characteristics of the singleton pattern, it can be applied to scenarios such as global unique configuration, database connection objects, file access objects, etc. In Go language, there are multiple ways to implement the singleton pattern. Today, let's learn together about some of these approaches.Eager InitializationImplementing the singleton pattern using eager initialization is very simple....

1,945 0       TUTORIAL GOLANG SINGLETON PATTERN


  Secure Your Go Code With Vulnerability Check Tool

Security vulnerabilities exist in any language and any code, some are written by ourselves, but more are from the upstream dependencies, even the underlying Linux. We have discussed the security protection methods for Go and Kubernetes Image in Path to a Perfect Go Dockerfile and Image Vulnerability Scanning for Optimal Kubernetes Security, in which the security scanning was performed based on generic.As the Go community grows, more and more open-source packages have caused more security vulnerabilities, which has raised the concern of Go officials, and then the security sc...

1,876 0       GOLANG GOSEC GOVULNCHECK


  Go channel explained

In Go, a channel is a type of concurrent data structure that allows two or more goroutines (Go's term for lightweight threads) to communicate with each other. Channels provide a way for goroutines to send and receive values, and they are an essential part of Go's concurrency model.Here's a simple example that demonstrates how to use channels in Go:package mainimport ( "fmt")func main() { // Create a new channel with the `make` function ch := make(chan int) // Start a new goroutine that sends the value 5 to the channel go func() { ch <- 5 }() // Read the value fro...

1,757 0       GOLANG CHANNEL