Here a few hints on extracting something to a package:
Only functions, variables and types with capital letters on package level are accessible from the "outside" (other packages or main)
A public function should only return types that are public as well
In your case you say personstruct
is defined inside the function Person
. That is not possible if you want it to be a return value of the function. You need to define it on package level. Also it should be exported since an exported function uses it.
Here a sample:
package returnperson
// PersonStruct defines ...
type PersonStruct struct {
// fields
}
// Person does ...
func Person() map[string]PersonStruct {
var people = map[string]PersonStruct{}
//do stuff
return people
}
-- edit --
I would further suggest to call the package itself person
and make it about managing a person, meaning the main item in this package would be a struct called Person
. returnperson
is more of a function name.
The package could also be about a list of persons (slice/map). Then maybe you want to call it personlist
and the main topic of the package would be managing a list of persons with the main struct maybe called PersonList
.
Just some suggestions to think about...