Go variable and constant explanation

catalogue variable statement initialization General form Type derivation Omit var use Anonymous variable Scope global variable local variable constant All codes screenshot reference resources variable The Go language variable name consists of letters, numbers and underscores. The first character cannot be a number. Use the var ...

Posted by unmash on Sat, 05 Mar 2022 01:21:48 +0100

Go interface: why is nil interface not equal to nil

Static and dynamic characteristics of interface The static characteristic of the interface is that the interface type variable has a static type. For example, the static type of the variable err in var err error is error. Having static types means that the compiler will type check the assignment operation of all interface type variables at ...

Posted by Xzone5 on Fri, 04 Mar 2022 20:45:29 +0100

i/o timeout. I hope you don't step into the pit of this net/http package

  The article is continuously updated. You can search "growth of golang Xiaobai" on wechat for the first time, and reply to [tutorial] to get a free video tutorial of golang. This article has been included in GitHub https://github.com/xiaobaiTech/golangFamily , there are complete test sites and growth routes for large factory int ...

Posted by roscor on Fri, 04 Mar 2022 04:27:33 +0100

Go language from introduction to specification - 6.3, go language io operation - io related package and bufio

Go language from introduction to specification - 6.3, go language io operation - io related package and bufio 1. Preface *** (I/O is not much to say here. A simple understanding is the input / output of data. Generally, we need to understand I/O before learning file operation and network programming, because files and networks are relat ...

Posted by atlanta on Fri, 04 Mar 2022 01:05:21 +0100

5, Process control

Sequential control Branch control Cycle control Sequential control Step by step from top to bottom Branch control Branch control is to give Cheng Xi a choice to execute Single branch Double branch Multi branch Single branch control //if conditional expression{ //} func main() { var age int fmt.Println("Please enter age") fmt.Scanln ...

Posted by MesaFloyd on Thu, 03 Mar 2022 22:40:04 +0100

Tired of a single black background? Come and beautify your terminal!

[introduction]: Go terminal output style library based on TUI. brief introduction Lip gloss is an exquisite terminal output style library, which is built based on TUI. You can DIY your own Go terminal style and define text style, background color matching, etc. Lip Gloss adopts an expressive and declarative method for terminal rendering. If y ...

Posted by gordonrp on Thu, 03 Mar 2022 22:31:47 +0100

http.FileServer and HTTP StripPrefix

http.FileServer func FileServer(root FileSystem) Handler The FileServer returns an HTTP processor that uses the file system interface root to provide file access services. To implement using the file system interface of the operating system, use HTTP Dir: http.Handle("/", http.FileServer(http.Dir("/tmp"))) Use cases of official docu ...

Posted by GremlinP1R on Thu, 03 Mar 2022 21:16:39 +0100

Solving the problem of time operation in golang gin framework orm time and time operation -- with source code

Question: compare the database time. The field has datetime type and int type (representing minutes). It is necessary to judge whether the timeout occurs The more you turn, the more problems you have. Simply use functions directly. analysis: The time structure is type Time struct { wall unit64 //Indicates the number of seconds from 00 ...

Posted by Phrank on Thu, 03 Mar 2022 21:07:36 +0100

15, Unit test

During development, it is necessary to confirm whether the results of a function and module are correct func addUpper(n int)int{ res:=0 for i := 1; i <n ; i++ { res+=i } return res } Traditional method testing is to call this function to see whether the returned result is correct Disadvantages: You need to call in the m ...

Posted by cigardude on Thu, 03 Mar 2022 20:56:40 +0100

Practice the design pattern of GoF 23: SOLID principle

Abstract: This paper will describe the interface isolation principle and Dependency Inversion Principle in SOLID principle. This article is shared from the Huawei cloud community "practice the design pattern of GoF 23: SOLID principle (Part 2)", author: yuan Runzi. In< Practice 23 design modes of GoF: SOLID principle (I) >In ...

Posted by Atanu on Wed, 02 Mar 2022 05:13:32 +0100