Multi-word Project Name

97 views
Skip to first unread message

iammadab

unread,
Apr 28, 2021, 4:14:55 PM4/28/21
to golang-nuts
Hi, I have a github repository name (sherlock-server) of which I have found no one word description that captures the essence.

There will be internal packages in it and so their imports will contain the above module name. 
What is the best way to name this module?

Thanks.

Sean Liao

unread,
Apr 28, 2021, 4:18:16 PM4/28/21
to golang-nuts
Yes that can be your module name, it won't affect much

iammadab

unread,
Apr 28, 2021, 4:39:41 PM4/28/21
to golang-nuts
Apparently, because it is a top level module and it won't be exporting anything it is actually fine.
Thanks.

Axel Wagner

unread,
Apr 28, 2021, 4:47:15 PM4/28/21
to iammadab, golang-nuts
FWIW the package name doesn't *have* to be the same as the import path. So even if it wasn't, you could name the package something else and still use that import path.
Otherwise, there would be the option to use `_`, which is valid inside an identifier.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/f31cf145-316b-4a68-b771-b3e4e692d310n%40googlegroups.com.

iammadab

unread,
Apr 28, 2021, 4:54:44 PM4/28/21
to golang-nuts
Assuming by package name your mean
package "packagename"
and import path
import "importpath"
Guess by "even if it wasn't" you mean "even if it wasn't top level and was exporting functionality"

but don't quite understand what you meant

Brian Candler

unread,
Apr 29, 2021, 3:19:05 AM4/29/21
to golang-nuts
> Guess by "even if it wasn't" you mean "even if it wasn't top level and was exporting functionality"

I think he means in general, you can do this:

package foo
...

and when you import it, you still get a package "foo".  That's unless you rename at import time, e.g.
import (
)

Here's a complete example.  To test, cd into pkg1 then do "go mod tidy && go run ."  Note that package foo (in directory pkg2) *is* top level and *is* exporting functionality.  

==> pkg1/go.mod <==

go 1.16


require example.com/my/module/with-a-very-weird-name v0.0.0-00010101000000-000000000000

==> pkg1/main.go <==
package main

import (
    "fmt"
)

func main() {
    fmt.Println(foo.Greeting)
}

==> pkg2/go.mod <==

go 1.16

==> pkg2/main.go <==
package foo
var Greeting = "Hello world"

Brian Candler

unread,
Apr 29, 2021, 3:28:37 AM4/29/21
to golang-nuts
P.S. I don't really recommend this, since you can't tell by inspection of main.go which import provides "foo.Greeting".  And I'm struggling to think of any real-world examples where I've seen this used.

Axel Wagner

unread,
Apr 29, 2021, 3:43:28 AM4/29/21
to Brian Candler, golang-nuts
Note that goimports theses days adds the package name explicitly to the import if the package name is not identical to the last component of the import path. So on the readability front, the cost seem pretty low to me.

It does have a cost on the writing side, as goimports might not find the package and there's always an extra step to figure out the package name if you start with the import path (e.g. a GitHub repo).

So yes, I would generally try to avoid it, but it's also not the end of the world :)

On Thu, Apr 29, 2021, 09:29 Brian Candler <b.ca...@pobox.com> wrote:
P.S. I don't really recommend this, since you can't tell by inspection of main.go which import provides "foo.Greeting".  And I'm struggling to think of any real-world examples where I've seen this used.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.

Brian Candler

unread,
Apr 29, 2021, 4:11:58 AM4/29/21
to golang-nuts
Sure.  In the OP's given path "github.com/username/sherlock-server", if it provides either "package sherlock" or "package server" it's not too bad.

Thanks for pointing me to goimports.  That does indeed rewrite the example as


Reply all
Reply to author
Forward
0 new messages