基礎實戰

Section 1

Section 1-1

# Create your project folder and cd inside
$ mkdir -p $GOPATH/src/github.com/username/project && cd "$_"
$ export GO111MODULE=on
$ go mod init github.com/appleboy/project

$ go mod download
$ go clean -i -x -modcache

section 1-2 govendor

$ mkdir -p $GOPATH/src/github.com/JasonYCHuang/project && cd "$_"

$ govendor init

$ govendor fetch github.com/gin-gonic/gin@v1.3

$ govendor sync

$ govendor add +external

Section 3

Section 3-1

  • 同一目錄下, 不含子目錄, 所有.go檔案的package要一樣

  • subpackage: package name = folder name; 則以下code使用

  • 只使用init, 則以下code使用

Section 3-2

global variable

Section 3-3

func return func

func as variable

anonymous

go func

Section 3-4

func 參數是slice => call by reference

immutable: append(slice, element)

Last updated