package specialAPIModels import ( I "devel.mephi.ru/dyokunev/wwwvoip/app/iface" "github.com/revel/revel" "voip/app/models" ) type Person struct { common Login *string `json:",omitempty"` Firstname string `json:",omitempty"` Lastname string `json:",omitempty"` Patronymic *string `json:",omitempty"` Displayname *string `json:",omitempty"` DisplaynameLatin *string `json:"displayname_latin,omitempty"` PhotoUrl string `json:"photo_url,omitempty"` ShowEmail interface{} `json:"show_email,omitempty"` } type Persons []Person func (persons *Persons) IConvert(apiHost string, affiliateUnit *models.Unit) (I.Slice, error) { var convertedPersons models.Subscribers convertedPersons = make([]models.Subscriber, len(*persons)) sem := make(chan bool, 512) i := 0 for _, person := range *persons { sem <- true go func(person Person, i int) { defer func() { <-sem }() revel.TRACE.Printf("person == %v", person) var convertedPerson models.Subscriber { specialPersonId := person.Id convertedPerson = models.Subscriber{ Firstname: person.Firstname, Lastname: person.Lastname, Patronymic: person.Patronymic, Key: int64(-(affiliateUnit.Code.Mid*100000 + person.Id%100000)), Login: person.Login, HasSecurityLevel: 50, SecurityLevel: -512, DisplayName: "", DisplayNameLatin: "", PhotoUrl: person.PhotoUrl, SourceAPIHost: &apiHost, SpecialAPIId: &specialPersonId, } convertedPerson.IsFake = false convertedPerson.Notes = "" } switch v := person.ShowEmail.(type) { case int: convertedPerson.ShowEmail = v != 0 case int64: convertedPerson.ShowEmail = v != 0 case float32: convertedPerson.ShowEmail = v != 0 case float64: convertedPerson.ShowEmail = v != 0 case bool: convertedPerson.ShowEmail = v case string: convertedPerson.ShowEmail = v != "0" case nil: convertedPerson.ShowEmail = true default: revel.ERROR.Printf("Unknown type of variable \"person.ShowEmail\", value: \"%v\", type: \"%T\"", v, v) } var err error convertedPerson.PhotoUrl, err = convertedPerson.DownloadRemotePhoto() if err != nil { revel.ERROR.Printf("Persons.IConvert(\"%v\", affiliateUnit) error: %v", apiHost, err.Error()) //return nil, err } convertedPerson.FixDisplayNames() convertedPersons[i] = convertedPerson }(person, i) i++ } for i := 0; i < cap(sem); i++ { sem <- true } return convertedPersons, nil }