On Wed, 11 Apr 2018, Ian Lance Taylor wrote:

> On Wed, Apr 11, 2018 at 6:11 AM, Robert P. J. Day <rpj...@crashcourse.ca> 
> wrote:
> >
> >   total beginner question here, but the docs seem vague or
> > inconsistent on what should be a simple question -- what does it mean
> > to import a name that is a single .a file versus importing a directory
> > name from under GOROOT (in my case, on fedora, /usr/lib/golang).
> >
> >   first, running on fedora 28 beta, go version 1.10.1, and i see the
> > directory structure /usr/lib/golang and, under that, the further
> > directory layout pkg/linux_amd64, which i assume is where go will
> > begin its search for packages i specify to import -- that directory
> > contains, at its top level:
> >
> > $ ls -F
> > archive/    debug/      html/      math/   plugin.a   sync.a
> > bufio.a     encoding/   html.a     math.a  reflect.a  syscall.a
> > bytes.a     encoding.a  image/     mime/   regexp/    testing/
> > cmd/        errors.a    image.a    mime.a  regexp.a   testing.a
> > compress/   expvar.a    index/     net/    runtime/   text/
> > container/  flag.a      internal/  net.a   runtime.a  time.a
> > context.a   fmt.a       io/        os/     sort.a     unicode/
> > crypto/     go/         io.a       os.a    strconv.a  unicode.a
> > crypto.a    hash/       log/       path/   strings.a  vendor/
> > database/   hash.a      log.a      path.a  sync/
> > $
> >
> > so far, so good.
> >
> >   now, when i, for example:
> >
> >   import "fmt"
> >
> > i assume that what is being imported is the package represented by
> > that single archive file, fmt.a, correct? that seems simple enough, as
> > there is no fmt/ directory, so my initial understanding is that an
> > import is meant to import the contents of a single ".a" go package
> > file.
> >
> >   consider, next, an example where there is both an archive file and a
> > corresponding subdirectory, say "hash.a" and "hash/". if i simply did
> > this:
> >
> >   import "hash"
> >
> > i'm *assuming* that would import the package corresponding to only the
> > archive file "hash.a", correct? if i wanted to import a hash
> > "subpackage" (say, hash/crc32.a), then the import would look like:
> >
> >   import "hash/crc32"
> >
> > which would import *only* that hash-related package. (i realize this
> > all sounds trivial, it would just be nice if the docs came right out
> > and said it.)
> >
> >   finally, what if there is no top-level .a file, and *only* a
> > subdirectory, such as for container/:
> >
> > $ tree container
> > container
> > ├── heap.a
> > ├── list.a
> > └── ring.a
> > $
> >
> >   given that there is no top-level container.a file, would it even
> > make any sense to say:
> >
> >   import "container"
> >
> > i realize this is all trivially trivial, but it would be nice if,
> > early in the docs, this was spelled out clearly and directly (unless,
> > of course, it is and i just haven't got to that section yet).
>
> The .a files under $GOROOT/pkg are most usefully thought of a cache
> of compiled code.

  ah, that clarifies bunches.

> When you import "fmt", you are importing the package named "fmt" in
> $GOROOT/src.  For any general non-relative import "a/b/c" the go
> tool will look in $GOROOT/src then in the src directory of each
> entry in $GOPATH.  The package in one of those src directories is
> always what is being imported.  The go tool may then decide to save
> some time by using the cached precompiled .a file in $GOROOT/pkg or
> $GOPATH/pkg.  In future releases of Go, it is quite possible that
> $GOPATH/pkg, and maybe even $GOROOT/pkg, will go away entirely, to
> be replaced by $GOCACHE.

  ah, it's all (i think) clear now. so, based on what i see under
${GOROOT}/src/hash, i could do any or all of the following:

  import "hash"
  import "hash/adler32"
  import "hash/crc32"
  import "hash/crc64"
  import "hash/fnv"

which all represent distinct imports. however, it would make no sense
to:

  import "container"

as there is no .go file immediately under that directory; rather, my
only options would be:

  import "container/heap"
  import "container/list"
  import "container/ring"

as long as i'm getting that right, it all seems so simple now, once
it's explained. :-)

  i might have a related question shortly after i read more. thank you
kindly.

rday

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

Reply via email to