github.com/adacta-ru/mattermost-server/v6@v6.0.0/model/integrity.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See LICENSE.txt for license information. 3 4 package model 5 6 import ( 7 "encoding/json" 8 "errors" 9 ) 10 11 type OrphanedRecord struct { 12 ParentId *string `json:"parent_id"` 13 ChildId *string `json:"child_id"` 14 } 15 16 type RelationalIntegrityCheckData struct { 17 ParentName string `json:"parent_name"` 18 ChildName string `json:"child_name"` 19 ParentIdAttr string `json:"parent_id_attr"` 20 ChildIdAttr string `json:"child_id_attr"` 21 Records []OrphanedRecord `json:"records"` 22 } 23 24 type IntegrityCheckResult struct { 25 Data interface{} `json:"data"` 26 Err error `json:"err"` 27 } 28 29 func (r *IntegrityCheckResult) UnmarshalJSON(b []byte) error { 30 var data map[string]interface{} 31 if err := json.Unmarshal(b, &data); err != nil { 32 return err 33 } 34 if d, ok := data["data"]; ok && d != nil { 35 var rdata RelationalIntegrityCheckData 36 m := d.(map[string]interface{}) 37 rdata.ParentName = m["parent_name"].(string) 38 rdata.ChildName = m["child_name"].(string) 39 rdata.ParentIdAttr = m["parent_id_attr"].(string) 40 rdata.ChildIdAttr = m["child_id_attr"].(string) 41 for _, recData := range m["records"].([]interface{}) { 42 var record OrphanedRecord 43 m := recData.(map[string]interface{}) 44 if val := m["parent_id"]; val != nil { 45 record.ParentId = NewString(val.(string)) 46 } 47 if val := m["child_id"]; val != nil { 48 record.ChildId = NewString(val.(string)) 49 } 50 rdata.Records = append(rdata.Records, record) 51 } 52 r.Data = rdata 53 } 54 if err, ok := data["err"]; ok && err != nil { 55 r.Err = errors.New(data["err"].(string)) 56 } 57 return nil 58 }