1条回答 默认 最新
douzong0711 2017-03-26 20:16关注First, the general structure of your Go workspace seems to be wrong. You need to make it look more like this:
D: |-- go_projects | |-- bin | |-- pkg | |-- src | | |-- FirstSteps | | | |-- main.go | | | +-- util | | | +-- myprinter.go | | |-- SecondProject | | |-- ThirdProject ...Second your
importstatement seems to be empty, I have no idea how goglang works but if you want to use whatever is in yourmyprinter.gofile, you will need to import theutilpackage, assuming that themyprinter.gofile declares itspackageasutilat the top.// FirstSteps/main.go package main import ( "FirstSteps/util" ) func main() { util.MyPrinterFunc() }And of course to be able to use anything from
utilthere first must be something...// FirstSteps/util/myprinter.go package util func MyPrinterFunc() { // do stuff... }Edit: I'm sorry, I didn't actually answer your question initially. You're getting the error
Cannot find package 'main'because of the wrong workspace setup I already mentioned. ThePackage pathtells Gogland where the package you want to run is relative to the$GOPATH/srcdirectory. So after you've setup your wrokspace correctly, you should set thePackage pathtoFirstStepssince that package's absolute path will be$GOPATH/src/FirstSteps. If, later, you want to run theutilpackage you would specifyPackage pathasFirstSteps/utilfor gogland to be able to find it.本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
