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

 PROGRAMMING


  A Sip of Go Log

Logging is indispensable in any code that we need its support both in debugging and in statistics. However, a package that filled withfmt.Println/fmt.Printf printing various messages can never be considered a read-to-be-adopted package, which can be optimized by a simple change, using Golang’s native log package to print information to standard output or to a file.Then, how to apply the log package? Are there any limitations? If so, can we seek open-source packages? Let’s find the answers together.Golang logpackage mainimport "log"func main() { log.Println("Log pri...

1,324 0       GOLANG LOGGING


  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,051 0       GOLANG PUBLISH PACKAGE GO.DEV


  When and Where to Use Pointers in Go

When declaring variables in Go, we usually have two syntax options: In some scenarios, pointers; in others, reference; sometimes, either. It’s great to have choices, but it is also confusing sometimes as to which one in which scenario.To be more reasonable in choice-making, I started from pointers, walked through their natures, and summarized some rules in using them in Go.from unsplash, Jordan LadikosPointersGo has pointers. A pointer holds the memory address of a value.— from A Tour of GoThe data is stored in the memory when the program runs and each has a num...

2,289 0       POINTER GOLANG


  Our Go Cache Library Choices

In Build a Go KV Cache from Scratch in 20 minutes, I walked you through what matters when writing a local cache, and eventually implemented one, whose performance was beaten badly by that of the popular go-cache on Github though. However, the bright side is that we can learn a lot from those excellent Github Go cache products, studying their features, applicable scenarios, and implementations, and extracting what we need.In this article, I will mainly analyze and compare the four cache libraries of go-cache, bigcache, golang-lru, and groupcache, which are all...

1,478 0       CACHE GOLANG GO-CACHE BIGCACHE GOURPCACHE


  golangci-lint to enable comment check for exported functions

golangci-lint is a command line tool which aggregates a list of different go linters to check whether the source code is in correct condition from different aspects. It is built to run during the CI pipeline so that there is no obvious coding issues before compiling and building the program.It is easy to run it with just below command$ golangci-lint run -vINFO [config_reader] Config search paths: [./ /Users /] INFO [config_reader] Used config file .golangci.yml INFO [lintersdb] Active 10 linters: [deadcode errcheck gosimple govet ineffassign staticcheck structcheck typecheck unused varcheck] I...

6,421 0       GOLANG GOLANGCI-LINT REVIVE GOLINT EXPORTED COMMENT


  The magic of go:linkname

When writing Go program, there is frequent need on using time.Sleep() function to pause the logic for some time. And if jumping to the definition of this function, can see below definition:// Sleep pauses the current goroutine for at least the duration d.// A negative or zero duration causes Sleep to return immediately.func Sleep(d Duration)I's strange that there is no function body defined here. What happened? The actual definition of the function body is residing at runtime/time.go indeed.// timeSleep puts the current goroutine to sleep for at least ns nanoseconds.//go:linkname tim...

11,525 0       TRICKS GOLANG GO:LINKNAME


  SkipList in Go

Algorithmic thinking is the must-have in the coding world, so I have been keeping the routine of algorithm practice every week, consolidating my knowledge of data structures on one hand, and improving my coding skills as well.A difficult one happened to be stuck in my mind- Implement SkipList with Go, which took me quite a weekend. Below is the front-line report of how I finally got the hang of it.First, from its concept. Wiki has explained it well.a skip list is a probabilistic data structure that allows O(log n) search complexity as well as O(log n) insertion co...

3,092 2       GOLANG SKIPLIST


  Popular Golang JSON libraries evaluation

JSON (Javascript Object Notation), a prevailing data exchange format, is widely used in various platforms and languages. Golang, of course, will never miss the support for JSON. And with its own standard library, such as those interfaces like the REST API from the API Service in Kubernetes, it can easily process JSON.Although Go’s library works great, we can still seek those open-source JSON libs in Github to maximize our efficiency. Then the features, performance, applicability of these libs are what we should put into consideration.And here comes my “evaluation report.”JSON...

7,332 0       FASTJSON JSON LIB JSON LIB COMPARISON GO-JSON