FAQ
Regards.

I have read the importpath help page, but I still have some doubts,
caused by the import paths used by gopkg.in and gopkg.cc.

A gopkg.in import path is in the form:
     import "gopkg.in/pkg.v3"
with the package name being pkg.

In go get a "dot extension" is used to explicitly specify the version
control system used,
however this is not the case for gopkg.in. Is gopkg.in "abusing" this go
get feature?

A gopkg.cc import path is in the form
     import "gopkg.cc/user/pkg/v0.1"
with the package name being pkg.

Here I simply don't understand how this is supposed to work with go get.


Thanks Manlio

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Nate Finch at Dec 3, 2014 at 6:52 pm
    Ok, so, first and foremost, the last part of the import path and the
    package name are not *required* to be the same. They are strongly
    suggested to be the same, but they are in fact completely independent. The
    import path is simply the path on disk inside your $GOPATH/src. Only "go
    get" translates this into a URL. Go build etc just expect it to be a path
    on disk, so you can have

    import "foo/bar"


    and as long as there's go code at $GOPATH/src/foo/bar, go build will work
    fine.

    Now the package name is whatever you put in the statement at the top of
    each file

    package "zzzz"

    You can put that package statement inside a go file in the aforementioned
    foo/bar path, and that'll work just fine. The code would look something
    like this:

    import "foo/bar"

    var a = zzzz.Something


    The reason it is suggested that you make the package name and the last part
    of the import path the same is just to make developers lives easier, so
    it's more obvious what the package name is and what import path it comes
    from.

    So... given all this, the import path

    import "gopkg.in/foo/bar.v2"


    Again, this just points to a path on disk to the go build tool. If you
    have a folder $GOPATH/src/gopkg.in/foo/bar.v2 ... the build tool will look
    for code in that folder. As for go get, it expects that to be a URL... and
    indeed, the gopkg.in website will serve up a URL at that path, with
    metadata that tells the go tool where to download the source code from.
      gopkg.in does a little git magic redirection to translate the git clone
    request from https://gopkg.in/foo/bar.v2 to git://github.com/foo/bar (v2
    branch). I'm not a git expert, so I can't comment on how exactly that code
    works, but, it does.

    And, as before, the package name is whatever is declared in the code inside
    that folder. Most likely, the package name for this code would be "bar",
    but in theory it could be anything.

    I hope that helps.

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Manlio Perillo at Dec 3, 2014 at 10:22 pm
    Il giorno mercoledì 3 dicembre 2014 19:52:06 UTC+1, Nate Finch ha scritto:
    Ok, so, first and foremost, the last part of the import path and the
    package name are not *required* to be the same. They are strongly
    suggested to be the same, but they are in fact completely independent. The
    import path is simply the path on disk inside your $GOPATH/src. Only "go
    get" translates this into a URL. Go build etc just expect it to be a path
    on disk, so you can have

    import "foo/bar"


    and as long as there's go code at $GOPATH/src/foo/bar, go build will work
    fine.


    [...]
    Thanks for the detailed explanation, it really helped to clarify my doubts.
    [...]

    Regards Manlio

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedDec 2, '14 at 11:00a
activeDec 3, '14 at 10:22p
posts3
users2
websitegolang.org

2 users in discussion

Manlio Perillo: 2 posts Nate Finch: 1 post

People

Translate

site design / logo © 2022 Grokbase