How to correct import files

I want to import into my main.go another go file
my file structure is following

-root
 --templ
 --main.go
 --others
   ---others.go

i want to import others.go inside my main.go but this path does not work

import "others/others.go"

You need to use the full path relative to the src folder in the $GOPATH. And also it’s enough to specify the containing folder.

1 Like

Sorry is it ok if my GOPATH is C:\Users\Akezhan\go and my work space is C:\Go\workSpace
My GOROOT C:\Go\ and in Path C:\Go\bin

You can do relative imports in golang, but then you can’t use qualified imports from the GOPATH anymore.

It is prefered to have your code in the GO-workspace (aka $GOPATH/src)

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.