I am trying to learn Go and to follow the existing conventions, but, as every convention, you need to first understand them before use them well, and after some research, I didn't find an exact answer to my following question:
I've set up a project inside my $GOPATH
, following a similar structure like this:
$GOPATH/
github.com/
username/
projectname/
main.go
numbers/
rational.go
real.go
complex.go
My main is:
package main
import(
"fmt"
"./numbers"
)
func main() {
fmt.Println(numbers.Real{2.0})
}
So, the questions are:
I read that I need to have a file
package.go
inside each package folder, is that right ?If so, inside
numbers.go
, how will I importrational.go
,real.go
andcomplex.go
?And then, is it possible to have something like:
// real.go package numbers type Real struct { Number float64 }
... and in main do fmt.Println(numbers.Real{2.0})
?