package natsio import ( "errors" "go.mongodb.org/mongo-driver/bson/primitive" ) // // Common // type IDAndName struct { ID string `json:"_id"` Name string `json:"name"` } // // USER // type User struct { ID primitive.ObjectID `json:"_id"` Name string `json:"name"` Type string `json:"type"` Avatar *FilePhoto `json:"avatar"` } func ParseToUser(data interface{}, result User) (err error) { b := InterfaceToBytes(data) if len(b) > 0 { err = json.Unmarshal(b, &result) } else { err = errors.New("[natsio.ParseUser] cannot read data") } return } // // FILE PHOTO // type FilePhoto struct { ID primitive.ObjectID `json:"_id"` Name string `json:"name"` Dimensions *FileDimensions `json:"dimensions"` } type FileSize struct { Width int `json:"width"` Height int `json:"height"` URL string `json:"url,omitempty"` } type FileDimensions struct { Small *FileSize `json:"sm"` Medium *FileSize `json:"md"` } func ParseToPhoto(data interface{}, result FilePhoto) (err error) { b := InterfaceToBytes(data) if len(b) > 0 { err = json.Unmarshal(b, &result) } else { err = errors.New("[natsio.ParsePhoto] cannot read data") } return }