I've been trying to find an answer to this question without success.
The question is about import statements in Go when a package consists of multiple source files.
Let's say I have a package called math
which consists of multiple files:
|-- math
|-- add.go
|-- subtract.go
|-- divide.go
|-- multiply.go
Let's assume that the math
package makes use of the fmt
package therefore it needs the appropriate import statement. But since we have four separate files, we have to import the fmt
package multiple times (at least to my understanding):
// add.go
import "fmt"
// subtract.go
import "fmt"
// divide.go
import "fmt"
// multiply.go
import "fmt"
Now the question is, what happens when the package is compiled? Are the statements simply merged together?
If so, why do we have to import the package multiple times (once per each file) and not just have a single file with all the import statements so as to not repeat ourselves?