There is a structure:

/golang --/project ----main.go ----/init ------start.go ----/init2 ------start2.go 

There is an error:

 cannot find package c:\golang\project\init\project\init2 

Main main.go file:

 package main import ( "./project/init" ) func main() { stat.Valid() } 

And broker start.go :

 package stat import ( "./project/init2" // И Π²ΠΎΡ‚ Ρ‚ΡƒΡ‚ я Ρ…ΠΎΡ‡Ρƒ ΠΈΠΌΠΏΠΎΡ€Ρ‚ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ init2 Π½ΠΎ ΠΌΠ½Π΅ Π½Π΅ Π΄Π°Π΅Ρ‚ ΠΈΠΌΠΏΠΎΡ€Ρ‚ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ, ΠΈΠ±ΠΎ выскакиваСт ошибка cannot find package c:\golang\project\init\project\init2 ) func Valid() { stat_two.Valid2() // Π΄ΠΎΠ»ΠΆΠ΅Π½ ΠΈΠΌΠΏΠΎΡ€Ρ‚ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒΡΡ ΠΏΠ°ΠΊΠ΅Ρ‚ stat_two ΠΈ функция Valid2 } 

And start2.go :

 package stat_two import ( "fmt" ) func Valid2() { fmt.Println("succ import!") } 

As I understood, another address is added to the address of the directory and it turns out to be c:\golang\project\init\project\init2 . How can I import another directory that is not in the current directory? To get c:\golang\project\init2 ?

  • mean "import directory"? packages are imported into Go - Abyx
  • @Abyx Changed, did not correct his question correctly. - Jack Anderson

1 answer 1

Importing a package higher level in GO

Well, note that the project code should be in GOPATH \ src (and not anywhere and not just in GOPATH)

  • Thank you very much! - Jack Anderson