Go Directives & Automation Tools Deep Dive

These go: instructions in the Go source code && go automation tools Developers have a strong tendency to automate repetitive tasks, and this also applies to writing code. Boilerplate code may include operations such as setting up a basic file structure, initializing variables, defining functions, or importing libraries or modules. In some cases, packages provide boilerplate code as a starting point for developers to build from, typically generated after the code behavior has been configured. Although boilerplate code may be necessary and valuable to application functionality, it can also be wasteful and redundant. For this reason, there are many tools that minimize boilerplate code. go generate is a command line tool for the Go programming language that allows automatic code generation. You can use go generate to generate easily modifiable code specific to your project, making the tool powerful at reducing boilerplate. go generate This command is usually used to automatically generate code before compilation. It can be used to create repetitive or patterned code, thereby saving time and reducing errors. Think about it, in what situations would this be particularly useful? 🤔 ...

January 25, 2024 · 22 min · 4561 words · Xinwei Xiong, Me

Use Go Tools Dlv

Debugging Go project prepare: + vscode + golang 1.92 demo go mod init test In main.go file package main import ( "fmt" ) // Swap functions func swap(x, y *string) (string, string) { //XOR exchange *x, *y = *y, *x } func main() { fmt.Println("Hello, world!") //Swap functions for i := 0; i < 10; i++ { a := "a" b := "b" swap(&a, &b) fmt.Println(a, b) } } vscode generates tests with one click >gotest for package/function ::: tip They are to generate test units for packages and test units for functions. ::: Generated as follows: ...

February 24, 2023 · 17 min · 3484 words · Xinwei Xiong, Me