package prosody import ( "log" "os" "reflect" "strings" ) type account struct { salt string `prosody:"salt"` storedKey string `prosody:"stored_key"` iterationCount int `prosody:"iteration_count"` } func (acc *account) unmarshal(data map[string]interface{}) { valueOfPerson := reflect.ValueOf(acc).Elem() typeOfPerson := valueOfPerson.Type() for i := 0; i < valueOfPerson.NumField(); i++ { field := valueOfPerson.Field(i) tag := typeOfPerson.Field(i).Tag.Get("mytag") if val, ok := data[tag]; ok { field.Set(reflect.ValueOf(val)) } } } // loadAccount read the user .dat file and retrieves the data store in it func (p *Prosody) loadAccount(username string) (*account, error) { var acc *account data, err := os.ReadFile(p.accountsPath + username + ".dat") if err != nil { return nil, err } lines := strings.Split(string(data), "\n") mapValues := make(map[string]interface{}) for _, line := range lines { if strings.Contains(line, "=") { parts := strings.Split(line, "=") key := strings.Trim(strings.TrimSpace(parts[0]), "[]\"") log.Println("key", key) value := strings.TrimSpace(strings.Trim(parts[1], "\"; ")) mapValues[key] = value } } acc.unmarshal(mapValues) return acc, nil }