如何从另一个文件夹导入主文件夹

This question already has an answer here:

app/main.go

package main

import (
   "fmt"
)
var varInMain string

func exm() {
    varInMain = "Hello, playground"

    fmt.Println(varInMain)
}

app/folder/call.go

package folder

import (
    "fmt"
    Main "../" -> ERR// or "app" -> ERR
)

func main() {

    fmt.Println(Main.varInMain)
}

I can not call main.go variable or func. from folder/call.go. How can i do it? //And thats must be local package

</div>

If you want to share vars across packages then create a separate package where you declare exported variables by the first character in caps.

app/mypack/vars.go

package mypack

var MyVar string

then import in main and other packages like package main

import (
    "fmt"
    mypack "app/mypack" 
)

func main(){
    mypack.MyVar = "Hello, playground"
}

same way import in app/folder/call.go and use

Main means that this package uses everything in your project(if not just remove it from your project and everything will be ok). And so you cannot import main because of cycle import. So you should create separate package and use it in main and in other packages if you want.