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

 GO


  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,125 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,506 0       JSON LIB COMPARISON JSON LIB FASTJSON GO-JSON


  Restore mocked variables in GoLang unit test

One of the guarding principles of writing unit test is that there should be no real external calls for dependant services. Unit test should run by its own and can run without issues on any environment including local, build, test environment. This indicates there should be some mock responses whenever an external call is needed so that different unit test scenarios can be covered.How can this be done in GoLang? In GoLang, anything can be assigned to a variable even including functions. A variable can be created to reference a function and it can be called just like a normal function when neede...

6,283 0       UNIT TEST GOLANG MOCK FUNCTION RESTORE MOCK


  combining dwarf failed: unknown load command 0x80000034 solution in GoLang

In case there is below error encountered while running some go program:combining dwarf failed: unknown load command 0x80000034This may be due to that you are running go 1.16 on a Mac M! machine. If you go to check go version, it may tell you that you are running an arm version of go.go version go1.16.10 darwin/arm64In such cases, you can try below methods to workaround the issue.Try to upgrade the go version to 1.17 and run the code again. If this is not an option for you because you have to stick to go 1.16 for some reason, you may try to install an amd version of go 1.16. This should work pe...

8,127 1       0X80000034 GO 1.16


  Go Error Best Practice

Being indulged in Go for quite a while and having implemented web-related programs, grpc interfaces and Operators, I seem to be an advanced beginner now.However, I am still a raw hand in production-environmental debugging, which is cumbersome if done by querying logs or error messages. Imagine the scenario that a full-text search is called when the specific location of the error log is missing. Then what happens when those error logs are not only in one place? Yes, my error logs can no longer help me locate the errors quickly and accurately.Apparently, the lack of the try {…} catch...

2,251 0       ERROR HANDLING GO ERROR


  The Go Pointer Magic

Go is a language with the pointer type, by which we canPass pointer into a function and update value in-place.Add methods to a struct as (* T) A, which is different from (T) A().However, the pointer is type-safe in Go, meaning that there are such restrictions of the pointer.Different types of pointers are unconvertible.Pointer type cannot be used for calculation.Pointer types cannot be compared, either == nor !=.No mutual assignment between different pointer-type variables.For example, *int cannot be converted to *int32in the following code.func main() {...

3,909 0       POINTER GOLANG UNSAFE


  Will nil == nil be true in GoLang

There is some interview question may ask whether nil == nil be true in GoLang. Wil it be true. false or compilation error? To know the answer, some knowledge about nil in GoLang needs to be explained first.nil definitionAccording to Go's official documentation, the definition of nil is// nil is a predeclared identifier representing the zero value for a// pointer, channel, func, interface, map, or slice type.var nil Type // Type must be a pointer, channel, func, interface, map, or slice typenil is the zero value of types like pointer, channel, func, interface, map or slice. Itself is NOT a GoLa...

5,717 2       GOLANG NIL NIL EXPLANATION


  Time to think about supporting max/min functions for integers in GoLang

Sometime back we wrote a post explaining why there is no max/min function support for integers in GoLang, one of the reasons is that no overloading is supported and the function name has been used for other numeric types float64. To solve this problem and make max/min function support integer as well, either GoLang should support overloading like in Java or the same set of functions need to be created in a different package other than standard math. These don't look like good options as overloading is more a OOP concept and supporting the same set of functions in a different package doesn't so...

4,887 0       GOLANG GENERICS MAX MIN