I am new at learning Go. I read that if I create a package and I use the install function that, that package will be available throughout my program. Yet after creating the following package and running the 'go install' command the package is not available to my program:
package person
import (
"fmt"
"time"
)
//Person struct
type Person struct {
FirstName, LastName string
Dob time.Time
Email, Location string
}
//PrintName method
func (p Person) PrintName() {
fmt.Printf("
%s %s
", p.FirstName, p.LastName)
}
//PrintDetails Method
func (p Person) PrintDetails() {
fmt.Printf("[Date of Birth: %s, Email: %s, Location: %s ]
", p.Dob.String(), p.Email,
p.Location)
}
and then creating the following main function either gives me 'syntax error: non-declaration statement outside function body' or it says the package is not found if I only use the package name which is what I learned I can do
package main
import (
"person"
)
p := Person {
FirstName : "Shiju",
LastName : "Varghese",
Dob : time.Date(1979, time.February, 17, 0, 0, 0, 0, time.UTC),
Email : "shiju@email.com",
Location : "Kochi",
}
p. PrintName()
p. PrintDetails()
What am I doing wrong please?