When I try to run my mainFile with this sample content:
package mainfolder
import cust "username/GoLearn/custompackage"
import custfunc "username/GoLearn/examplepackage"
func main() {
custfunc.examplefile2function() //this will be reported as not found
custfunc.examplefile1function() //this will be found and can be executed normally
cust.customfilefunction() //this will be found and can be executed normally
}
I don’t exactly know why my newly created examplefile2 was not picked up by Golang, what I have tried so far is to use
custfunc.Examplefile2function() //this will be reported as not found
custfunc.Examplefile1function() //this will be found and can be executed normally
cust.Customfilefunction() //this will be found and can be executed normally
BTW, the package that contains func main() must be named package main. Otherwise, the Go compiler cannot build an executable.
it surely solved my problem, thank you so much Christopher.
Out of the box, is there any document about rules in Golang ? I’m new so maybe mistaking things a lot
Go to the official website of the go.dev, golang is not very difficult, you can get started with it with a while, but the depth of things still needs to be specialized.
This is a port from Learn Go in Y Minutes, but with code examples that you can run right from within the browser. (You may find differences between this and the original page. Blame me for that. I ported the original page over and took the liberty to restructure a few things and add generics.)