golang project structure

58 阅读1分钟
go help env
go env: Env prints Go environment information.
go env -w GOPROXY=https://goproxy.cn,direct

GOROOT/GOPATH

Project
  utils
    sub
      xx.go  -- package sub, import "test/utils/sub"
    x1.go  -- package utils, import "test/utils"
    x2.go  -- package utils
  main.go  -- package main
  go.mod  -- module test (whatever)

may be import github repo in source code
then should exec $ go mod tidy
the repo will download into GOPATH/pkg/mod/
# go.mod content
module test
go 1.21
require github.com/xxx/xxx v1.0.0