You have to encapsulate this in another package. For example your main.go may look like:
package main
import (
"fmt"
"path_to_to/types"
)
func main() {
user := types.NewUser("Jack", "Amazon", "guard")
user.SetCompany("Google")
fmt.Printf("%#v\n", user)
}
And then your types package (in types folder) would contain something like:
package types
type User struct {
company string
role string
country string
}
func NewUser(company, role, country string) *User {
return &User{
company: company,
role: role,
country: country,
}
}
func (u *User) SetCompany(company string) {
u.company = company
}
func (u *User) SetRole(role string) {
u.role = role
}