natsio/model.go

69 lines
1.1 KiB
Go
Raw Permalink Normal View History

2022-12-04 17:09:25 +00:00
package natsio
import (
"errors"
)
2022-12-04 17:09:25 +00:00
2022-12-21 04:38:29 +00:00
//
// Common
//
type IDAndName struct {
ID string `json:"_id"`
Name string `json:"name"`
}
2022-12-18 03:56:37 +00:00
//
// USER
//
type User struct {
2023-01-11 12:55:25 +00:00
ID string `json:"_id"`
Name string `json:"name"`
Type string `json:"type"`
Avatar *FilePhoto `json:"avatar"`
2022-12-18 03:56:37 +00:00
}
2023-01-16 01:42:26 +00:00
func ParseToUser(data interface{}, result *User) (err error) {
b := InterfaceToBytes(data)
if len(b) > 0 {
2023-01-16 01:42:26 +00:00
err = json.Unmarshal(b, result)
} else {
err = errors.New("[natsio.ParseUser] cannot read data")
}
return
}
2022-12-18 03:56:37 +00:00
//
// FILE PHOTO
//
2022-12-04 17:09:25 +00:00
type FilePhoto struct {
2023-01-11 12:55:25 +00:00
ID string `json:"_id"`
Name string `json:"name"`
Dimensions *FileDimensions `json:"dimensions"`
2022-12-04 17:09:25 +00:00
}
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"`
}
2023-01-16 01:42:26 +00:00
func ParseToPhoto(data interface{}, result *FilePhoto) (err error) {
b := InterfaceToBytes(data)
if len(b) > 0 {
2023-01-16 01:42:26 +00:00
err = json.Unmarshal(b, result)
} else {
err = errors.New("[natsio.ParsePhoto] cannot read data")
}
return
}