Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusion about the name of go module #33274

Closed
shenshouer opened this issue Jul 25, 2019 · 5 comments
Closed

Confusion about the name of go module #33274

shenshouer opened this issue Jul 25, 2019 · 5 comments

Comments

@shenshouer
Copy link

What version of Go are you using (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?

@shenshouer
Copy link
Author

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")
}

@shenshouer shenshouer changed the title Doubts about the name of go module Confusion about the name of go module Jul 25, 2019
@ccbrown
Copy link

ccbrown commented Jul 25, 2019

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".

@bcmills
Copy link
Contributor

bcmills commented Jul 25, 2019

@ccbrown has it right. Module paths with a dotless first element are allowed, but are in general reserved for the standard library.

@bcmills
Copy link
Contributor

bcmills commented Jul 25, 2019

Duplicate of #32819

@bcmills bcmills marked this as a duplicate of #32819 Jul 25, 2019
@bcmills bcmills closed this as completed Jul 25, 2019
@shenshouer
Copy link
Author

@ccbrown I see, Thanks

@golang golang locked and limited conversation to collaborators Jul 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants