3 ms·
What does "github.com/godbus/dbus/v5" mean in a golang import? I've only ever seen the standard github.com/user/repo. I'm not sure what the v5 means. There is n
by herpderperator 6y ago
What does "github.com/godbus/dbus/v5" mean in a golang import? I've only ever seen the standard github.com/user/repo. I'm not sure what the v5 means. There is no branch/tag called "v5" in that repo, but there is one called v5.0.
Later in the code there is a line like
conn, err := dbus.SystemBus()
but how does golang it know it's referring to the dbus package if there's a v5 at the end? I thought it infers the name from the last part of the URL if it's not prefixed with an alias.
Sorry if this is a stupid question.
- jand 6y agoHere you go: https://blog.golang.org/using-go-modules https://blog.golang.org/using-go-modules Your v5 question should be answered by "part 4": https://blog.golang.org/v2-go-modules https://blog.golang.org/v2-go-modules
- kodah 6y agoV5 isn't actually a file path. It's a permanent part of the import path in go.mod that indicates the major version.
- TheDong 6y ago> I thought it infers the name from the last part of the URL if it's not prefixed with an alias. The name and the last part of the url are unrelated. They're only usually the same by convention. For example: import ( "fmt" "github.com/dimuska139/go-email-normalizer" ) func main() { fmt.Println(emailnormalizer.NewNormalizer().Normalize("x+1@gmail.com")) } The reason that I use "go-email-normalizer" as "emailnormalizer" is entirely unrelated to the url it's at or the name of the repo it's in. The only reason you use "emailnormalizer" is because that's the package line in all the files in that package: https://github.com/dimuska139/go-email-normalizer/blob/0432b8b7035/normalizer.go#L1 https://github.com/dimuska139/go-email-normalizer/blob/0432b... Importing a go package will add an arbitrary identifier to the file scope, and you can't know that identifier without reading the package statement of the package you imported.