Function in same package undefined

前端 未结 9 2066
太阳男子
太阳男子 2020-12-28 12:17

My project structure is like this.

packagetest/
    main.go
    lib.go

In main.go, I have this code.

package m         


        
9条回答
  •  一个人的身影
    2020-12-28 12:56

    I think the problem is you can only have one file using package main.

    Try putting lib.go in a different package. This requires:

    1. lib.go to exist in a folder with the same name as the new package (e.g., myLibs).

    2. Adding the package name to lib.go (package myLibs).

    Then, in main:

    import myLibs
    call myLibs.Test()
    

提交回复
热议问题