• 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, […]

  • Go- reflection


    reflex Basic introduction of reflection 17.3.1 basic introduction1) Reflection can dynamically obtain various information of variables at runtime, such as the type and kind of variables2) If it is a structure variable, you can also obtain the information of the structure itself (including the fields and methods of the structure)3) Through reflection, you can modify […]

  • 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 […]

  • Excellent resources of go language are sorted out to accelerate the implementation of the project;


    Last updated on November 22, 2019 Go language excellent resources arrangement, accelerating the project implementation A kind of Stable update on GitHub, think it’s good, please order a star Mei A kind of If you want to share, please keep the source. Thank you A kind of Original address: GitHub: Official website: […]

  • Using go language to build websocket server


    Go to build a simple websocket server code example test.go, as follows: package main import ( “fmt” “log” “net/http” “” ) func Echo(ws *websocket.Conn) { var err error for { var reply string if err = websocket.Message.Receive(ws, &reply); err != nil { fmt.Println(“Can’t receive”) break } fmt.Println(“Received back from client: ” + reply) msg := […]

  • go-redis


    redis Basic introduction to Redis Redis is a NoSQL database, not a traditional database, with high performance. It is suitable for caching and persistence. It is a fully open-source, free and high-performance distributed memory database. It runs based on memory and supports persistence. It is one of the most popular NoSQL databases, also known as […]

  • 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. […]

  • Go GTK environment configuration


    Go GTK environment configuration (graphical interface for go) After a day, I finally set up this environment, which is about msys2 – “installing various versions of GTK -” installing MinGW (I installed it but it doesn’t affect it, because I have to change the environment variable to this one, so it’s useless to install that […]

  • 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 […]

  • GO summary


    1. Foundation Go language introduction and development environment configuration Go- package Go data type and variable, constant Go – get variable data type Go arrays and slices Go slice copy and assignment Go- function Go- closure Go logical judgment (if, else if, else, switch) Go-for cycle Go-map Go – & get address and * dereference […]

  • Go data structure


    data structure Introduction of data structure (algorithm) Introduction to data structure 1) Data structure is a subject of algorithm research. Data structure only comes from programming language. Learning data structure well can writeMore beautiful, more efficient code.2) To learn a good data structure, we need to think about how to solve the problems in our […]

  • 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 […]