package credential import ( "encoding/json" "errors" "reflect" "git.loafle.net/overflow/model/meta" ) type Credential struct { } // CredentialsMap is map of array of Credential type CredentialsMap map[string]interface{} func (m *CredentialsMap) UnmarshalJSON(data []byte) error { credentials := make(map[string]json.RawMessage) err := json.Unmarshal(data, &credentials) if nil != err { return err } result := make(CredentialsMap) for k, v := range credentials { var i interface{} switch meta.ToMetaCredentialTypeEnum(&meta.MetaCredentialType{Key: k}) { case meta.MetaCredentialTypeEnumSNMP: var _i []*SNMPCredential i = &_i case meta.MetaCredentialTypeEnumWindows: var _i []*WindowsCredential i = &_i default: return errors.New("Unrecognized Credential") } err := json.Unmarshal(v, &i) if nil != err { return err } result[k] = reflect.ValueOf(i).Elem().Interface() } *m = result return nil } func unmarshalJSON(v json.RawMessage, i interface{}) error { err := json.Unmarshal(v, &i) if nil != err { return err } return nil }