A Go module is a collection of packages.  The packages are in a tree of 
directories (Go requires all files in one directory to be part of the same 
package), and there is a go.mod file at the root of the tree.

Users import packages individually, not the whole module.  go.mod documents 
the dependencies of this module, not the packages which this module 
contains.

Perhaps a real-world example will be helpful.  I often use the "assert" 
package from the "github.com/stretchr/testify" module:

package main

import (
        "github.com/stretchr/testify/assert"
"testing"
)

func TestSanity(t *testing.T) {
    assert.Equal(t, 2, 1+1)
}

Have a look carefully at the import statement.  The package I am importing 
is this directory of files:
https://github.com/stretchr/testify/tree/master/assert

Each of those files contains "package assert" - it's conventional (but not 
required) that the package name match the directory name. However, there is 
no go.mod in that directory.

You will find go.mod in the parent directory:
https://github.com/stretchr/testify/blob/master/go.mod

This directory could contain go source files, although in this case it does 
not.  If it did contain the source for another package, the import path for 
that package would be https://github.com/stretchr/testify.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/8ce4d3de-766c-4d9c-a820-088e6934d683o%40googlegroups.com.

Reply via email to