包以返回结构图

I have created the logic to populate a map of structs and it is working as expected. Now, I would like to move that functionality to a package. Like so

package returnperson
func Person() map[string]personstruct {
   //do stuff
   return people
}

I defined the personstruct in the body of the function Person, however, line 2 is throwing the following error:

undefined:personstruct(2,1)

I've researched and I don't seem to find a way to correct the issue. Thanks in advance for your help.

Here a few hints on extracting something to a package:

  1. Only functions, variables and types with capital letters on package level are accessible from the "outside" (other packages or main)

  2. 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...