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

 ALL


  Ensuring Go Interface Implementation: A Quick Guide

IntroductionGo's simplicity and power shine in its interface system, offering a clean way to define contracts between types. However, when it comes to checking whether a struct satisfies an interface, Go's static typing philosophy means there isn't a direct runtime check. In this concise guide, we'll explore practical methods, including some lesser-known tricks, to verify whether a struct implements an interface.Method 1: Type Assertion and a Dummy Methodpackage mainimport "fmt"type MyInterface interface { MyMethod()}type MyStruct struct{}func (ms MyStruct) MyMethod() { fmt.Println("MyMe...

914 0       INTERFACE GOLANG IMPLEMENTS


  new() and make() in GoLang

GoLang is a modern, statically typed, compiled programming language designed for building scalable, concurrent, and efficient software. It provides various built-in functions and features that help developers write concise and efficient code. Among them are the new() and make() functions, which may appear similar at first glance but serve different purposes in GoLang and are crucial for memory allocation and data initialization.In this blog article, we will explore the differences between the new() and make() functions, and understand when and how to use them effectively.new() and make()new() ...

1,123 0       MAKE GOLANG NEW


  Guide to Implement an SSH Client Using Golang

SSH, short for Secure Shell, is a network protocol used for securely remote logging into other computers on a network. I believe most backend developers are familiar with SSH. Common shell tools used for logging into servers, such as Xshell, SecureCRT, and iTerm2, are all based on the SSH protocol. In Golang, the crypto/ssh package provides functionality for implementing an SSH client. In this article, we will explain in detail how to implement an SSH client using Golang.Creating SSH Client ConfigurationFirst, we need to configure the parameters for the SSH client to connect to the server. The...

3,231 0       SSH GUIDE GOLANG SSH CLIENT


  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,877 0       GOLANG SINGLETON PATTERN TUTORIAL


  What can select do in GoLang

In Go language, select is a keyword used to listen to and perform IO operations related to channels.With the select statement, we can simultaneously listen to multiple channels and perform corresponding operations when any of the channels are ready.This article will summarize the common uses of the select statement and provide some considerations when using it.Basic syntaxThe basic syntax of the select statement is as follows:select {case <-channel1: // when channel1 has data to processcase data := <-channel2: // when channel2 has data to processdefault: // if no channel has dat...

1,091 0       GOLANG SELECT USAGE SYNTAX TUTORIAL


  errGroup in GoLang explained

Today, let's talk about the usage and applicable scenarios of errGroup, which is often used. Why is it useful? Generally, when we use goroutine, we cannot return a value. If you want to pass out the result of the goroutine execution, you usually have to use the channel. The errGroup package is suitable if you want to know when the goroutine you opened encounters an error during execution and stop working, and I need to know the error value.errGroup usageThe package needs to be downloaded and installed first. go get -u golang.org/x/syncAn example of using it would bepackage mainimport ( ...

4,696 0       CONCURRENCY WAITHROUP ERRGROUP GOLANG


  Go是一门面向对象的编程语言吗

Golang已经开源了13年,在最近的TIOBE编程语言排名中,于2023年3月再次进入前十名,并比2022年底的排名上升了两个位置。Go在2022年底提高了2个排名许多第一次接触Go的开发者来自面向对象的编程语言,比如Java、Ruby等,他们在学习Go后第一个问题通常是:Go是一种面向对象的语言吗?在本文中,我们将探讨这个问题。追溯在广为人知的Go编程语言“圣经”《The Go Programming Language》中,有一个Go与其主要祖先编程语言之间的亲缘关系图表。Go与其主要祖...

1,032 0       OOP GOLANG CHINESE GO


  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,160 0       SOURCE CODE GOLANG WAITGROUP