go version)?$ go version go version go1.12.7 darwin/amd64 and go version go1.12.6 darwin/amd64
I build a project at dir name container, with main.go in dir.
./container
├── go.mod
├── go.sum
└── main.go
Cannot build the project if the module name is container, the content of go.mod :
module container
go 1.12
require (
github.com/gin-gonic/gin v1.4.0
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/spf13/viper v1.4.0
gopkg.in/tylerb/graceful.v1 v1.2.15 // indirect
)
And build error: can't load package: package container: no Go files in /usr/local/go/src/container
It worked fine if I change the name of module with github.com/shenshouer/container
module github.com/shenshouer/container
go 1.12
require (
github.com/gin-gonic/gin v1.4.0
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/spf13/viper v1.4.0
gopkg.in/tylerb/graceful.v1 v1.2.15 // indirect
)
Must the name of module be like github.com/shenshouer/container?
main.go:
package main
import (
"flag"
"fmt"
"os"
"github.com/gin-gonic/gin"
"github.com/golang/glog"
"github.com/spf13/viper"
)
func usage() {
fmt.Fprintf(os.Stderr, "usage: example -stderrthreshold=[INFO|WARN|FATAL] -log_dir=[string]\n")
flag.PrintDefaults()
os.Exit(2)
}
var configFilePath string
func init() {
_ = flag.Set("alsologtostderr", "true")
flag.Usage = usage
flag.StringVar(&configFilePath, "config", "./config.yaml", "Config File Path")
flag.Parse()
viper.SetConfigType("yaml")
viper.SetConfigFile(configFilePath)
}
func main() {
glog.Infoln("FFF")
router := gin.Default()
// router.Use(middleware.CORS())
// api.V1(router, db, conf)
// glog.Infof("Start http server at: %s", conf.Address)
// graceful.Run(conf.Address, conf.GracefullyShutdownTimeout, router)
router.Run("8888")
}
The module name doesn't have to be "github.com/shenshouer/container", but it can't just be "container". In general, names without dots in the first component are reserved for standard library packages, and there is in fact a standard library directory named "container" already.
You can make up something like "example.com/container" if you really don't want to use your GitHub path, but it's recommended that you use a full go getable and importable path like "github.com/shenshouer/container".
@ccbrown has it right. Module paths with a dotless first element are allowed, but are in general reserved for the standard library.
Duplicate of #32819
@ccbrown I see, Thanks
Most helpful comment
The module name doesn't have to be "github.com/shenshouer/container", but it can't just be "container". In general, names without dots in the first component are reserved for standard library packages, and there is in fact a standard library directory named "container" already.
You can make up something like "example.com/container" if you really don't want to use your GitHub path, but it's recommended that you use a full
go getable andimportable path like "github.com/shenshouer/container".