natsio/model.go

69 lines
1.1 KiB
Go
Raw Normal View History

2023-04-27 04:19:33 +00:00
package natsio
import (
"errors"
)
//
// Common
//
type IDAndName struct {
ID string `json:"_id"`
Name string `json:"name"`
}
//
// USER
//
type User struct {
ID string `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 string `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
}