In Go, two or more files with the same package name are considered one package, meaning everything is accessible within the namespace, including private (lowercased) and public (capitalized) symbols.
For instance, if hashtable.go
and linkedlist.go
share the same package name:
package hashtable
import (
...
)
Then both are considered the same file.
However, if they have different package name, the best practice is to keep them in separate directory.
// hashtable.go
package hashtable
import (
...
)
type Hashtable struct {}
// linkedlist.go
package linkedlist
import (
...
)
type Linkedlist struct {}
Then organizing them this way:
project/
├── hashtable
| └── hashtable.go
└── linkedlist
└── linkedlist.go
And for example, in hashtable.go
, import linkedlist
to use its public variables:
// hashtable.go
package hashtable
import (
../linkedlist
)
li = linkedlist.Linkedlist{}