Think before you speak, read before you think.

Category: Golang

  • godocc

    $ go install github.com/inancgumus/godocc $ which godocc /Users/jpuyy/go/bin/godocc # example $ godocc fmt printf package fmt // import “fmt” func Printf(format string, a …any) (n int, err error) Printf formats according to a format specifier and writes to standard output. It returns the number of bytes written and any write error encountered.

  • golang fmt

    https://pkg.go.dev/fmt # %g %g %e for large exponents, %f otherwise. Precision is discussed below. fmt.Printf(“%g feet is %g meters.\n”, feet, meters)

  • golang interface

    learn by doing Interface is a protocol – a contract – an abstract type It only describe the expected behavior naming convention: abstract description don’t use empty interface unless it’s necessary. type foo interface{} learn type switch: func format(v interface{}) string { switch v := v.(type) { case int: case string: default: } } When…

  • golang mod

    go mod init go mod tidy

  • Go GoLand 配置

    安装 brew install go GOROOT 就是安装路径,不用管,会自动设置好 GOPATH 为存放 go 项目和依赖的地方 mkdir -p ~/go go 的子命令 go env GoLand Editor/General/Appearance/Show whitespaces 配置 File Watchers 进行 gofmt

  • golang 交叉编译

    编译 linux 64 位 GOOS=linux GOARCH=amd64 go build 编译 mac 64 位 GOOS=darwin GOARCH=amd64 go build