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



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 (

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.



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.



All Articles