News for hackers. Stuff that matters.
Re:Systemd Inhibitor Locks Deep Dive by herpderperator on Saturday April 10, 2021 @07:29PM (#26766262)
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.

Re:Systemd Inhibitor Locks Deep Dive by TheDong on Saturday April 10, 2021 @11:55PM (#26767368)
> 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("[email protected]"))
    }
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/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.

Re:Systemd Inhibitor Locks Deep Dive by jand on Saturday April 10, 2021 @07:37PM (#26766310)
Here you go:

https://blog.golang.org/using-go-modules

Your v5 question should be answered by "part 4":

https://blog.golang.org/v2-go-modules

Re:Systemd Inhibitor Locks Deep Dive by kodah on Saturday April 10, 2021 @07:46PM (#26766366)
V5 isn't actually a file path. It's a permanent part of the import path in go.mod that indicates the major version.