models/msg.go (raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
package models import ( "encoding/json" "time" ) type Datagram struct { Id string `json:"id"` Uri string `json:"uri"` Protocol string `json:"protocol"` Adapter string `json:"adapter"` Type string `json:"type"` Target *string `json:"target,omitempty"` } type Message struct { Datagram Author string `json:"author"` Content string `json:"content"` Attachments []Attachment `json:"attachments"` ReplyTo *string `json:"replyTo"` Replies []string `json:"replies"` ReplyCount int `json:"replyCount"` Mentions []string `json:"mentions"` Created time.Time `json:"created"` Edited *time.Time `json:"edited,omitempty"` Visibility string `json:"visibility"` } type Author struct { Datagram Name string `json:"name"` ProfileData interface{} `json:"profileData"` ProfilePic string `json:"profilePic"` Messages []string `json:"messages,omitempty"` } type Attachment struct { Src string `json:"src"` ThumbSrc string `json:"thumbSrc"` Desc string `json:"desc"` CreatedAt time.Time `json:"createdAt"` Size uint64 `json:"size"` } type SocketData interface { ToDatagram() []byte } func (self Message) ToDatagram() []byte { data, err := json.Marshal(self) if err != nil { panic(err.Error()) } return data } func (self Author) ToDatagram() []byte { data, err := json.Marshal(self) if err != nil { panic(err.Error()) } return data } |