• Learn unit testing, say goodbye to prayerful programming


    Prayer programming Prayer programming If the code contains the following code Or after going online So this way of programming is prayerful programming. It’s basically like this in a flowchart. What’s the harm of prayerful programming? Tired, I need to pray every time I finish writing the code Uncontrollable. The result of code running depends […]

  • A method to output SQL result set in JSON format by golang


    In this paper, an example is given to show how to output SQL result set in JSON format in golang. To share with you for your reference, as follows: Copy codeThe code is as follows: func getJSON(sqlString string) (string, error) {     stmt, err := db.Prepare(sqlString)     if err != nil {         return nil, […]

  • Semantic Versioning on Private Library Package for Golang 1.13


    What we need? Golang version 1.13 or above GOPRIVATE introduced to go module since 1.13 multi section of GOPROXY introduced to go module since 1.13 Running Gitlab Certainly, We need it host our private code. I assumed your gitlab running happily at http://foo.bar.com Configure go.mod file for Library Package Init a package named group/project go […]

  • Golang’s judgment on map, deletion example


    The example of this paper describes the judgment and deletion operation of golang for map. To share with you for your reference, as follows: Map is a key value relationship. Generally, make is used to initialize memory, which helps to reduce the number of memory allocation for subsequent new operations. If it is defined at […]

  • Golang RPC practice


    Absrtact: Generally speaking, each HTTP request is a waste of resources. Although HTTP is also on top of TCP, HTTP requests add a lot of their own information, which will consume bandwidth resources. So some companies use RPC as the communication protocol of internal application. original text If you are interested in Go, you can […]

  • Implementation principle of golang defer


    Defer is a keyword supplied by golang, which is called before the function or method is executed and returned.Every time defer will push the defer function into the stack. When a function or method is called, it will be taken out of the stack for execution. Therefore, the execution order of multiple defer is first […]

  • An example of generating integer random number with golang


    PHP random number To generate a random number with a given range, it’s too easy to use PHP, and you can specify the range from a negative number to a positive integer, such as: <?php echo mt_rand(-988, 888); This randomly generates – 988 to 888 random numbers. It’s a little more difficult to use go. […]

  • Interface understanding of go


    Go language does not have the concept of object-oriented. The interface mentioned in go language is different from that mentioned in Java, C + + and other languages. It does not show that it implements the interface without inheritance, subclass and implementation keywords. Go language realizes the interface function in a recessive way, which is […]

  • How to call Linux command with golang


    This article introduces that golang uses OS / exec to execute linux commands, which is shared for your reference and learning. Here is a detailed introduction: Here is a simple example: package main import ( “fmt” “io/ioutil” “os/exec” ) func main() { cmd := exec.Command(“/bin/bash”, “-c”, `df -lh`) //Create get command output pipeline stdout, err […]

  • Analysis of go map principle


    In the process of using map, two problems are often encountered: read-write conflict and traversal disorder. Why is this so? How is the bottom layer implemented? With these two problems, I have a simple understanding of the implementation of map addition, deletion, modification, query and traversal. structure hmap type hmap struct { // Note: the […]

  • Explanation and difference of golang function and function and method


    Gorang function and the difference between function and method Before I came to go, I thought functions and methods were just two names of the same thing (there was no obvious difference in my familiar C / C + +, python, Java), but in golang, they were two different things. The official explanation is that […]

  • A tutorial on reading and writing excel in golang


    introduce Excellize is a class library of office EXCEL documents written by golang, which is based on Microsoft’s office openxml standard. It can be used to read and write xlsx files. Compared with other open source libraries, excel supports writing original documents with pictures (tables), inserting pictures into excel, and does not lose chart styles […]