diff --git a/config.go b/config.go index 63be3ff..47a9910 100644 --- a/config.go +++ b/config.go @@ -18,6 +18,10 @@ type config struct { users map[string]string } +type rawConfig struct { + Users []User +} + type User struct { Username string Password string @@ -34,22 +38,20 @@ func (p *parser) Parse(any *anypb.Any) (interface{}, error) { v := configStruct.Value conf := &config{} - var users []User + rc := &rawConfig{} - if userMap, ok := v.AsMap()["users"]; ok { - data, err := json.Marshal(userMap) - if err != nil { - return conf, err - } - - err = json.Unmarshal(data, &users) - if err != nil { - return conf, err - } + data, err := v.MarshalJSON() + if err != nil { + return nil, err + } - conf.users = paresUser2Map(&users) + err = json.Unmarshal(data, rc) + if err != nil { + return nil, err } + conf.users = paresUser2Map(&rc.Users) + return conf, nil }