douweng3564 2019-06-02 11:27
浏览 33

两个go文件,其中包声明主要位于包中

So i have created a package named app inside which there are two go files named entry.go and entry1.go where entry.go is having function main while entry1.go is having a function which is being called by entry.go.

content of entry.go:

package main 

import "fmt"
import "app"

func main(){
    fmt.Println("app/entry.go")
    app.FunctionOne()
}

content of entry1.go:

package main

func FunctionOne() {
    fmt.Println("this is having different name")
}

on running go build it shows import cycle

  • 写回答

1条回答 默认 最新

  • dongzhuonao8429 2019-06-02 11:44
    关注

    You don't have to import app! you're in the same package which is main package.

    just remove the extra import, and use FunctionOne() no need for app

    评论

报告相同问题?