Create with multiple files in GO (GO1)

Does anyone know if the "go build" command can be used to build from multiple files in a directory? for example

src/
  file1.go
  file2.go

      

Where file1.go contains func main () method and file2 provides supporting functions. I have tried using the following import statements but I am not getting there

import (
  "file2"
)

import (
  file2 "./file2"
)

      

I am wondering if this is the case that I need to change the GOROOT environment variable in order to get this to work. Or if I just get tired and miss something blindingly obvious.

thank

+3


source to share


1 answer


If file1.go and file2.go are part of the same package, this should work fine. You don't need to import files from one package into each other. Their variables and functions are already separated.



If the files belong to different packages, they must be in different directories.

+5


source







All Articles