package model import ( "fmt" "strconv" "strings" "time" ) type Message struct { ID string `json:"id"` RepTo string `json:"rep_to"` EchoArea string `json:"echo_area"` Date time.Time `json:"date"` From string `json:"from"` Addr string `json:"addr"` MsgTo string `json:"msg_to"` Subject string `json:"subject"` Message string `json:"message"` } func (m *Message) Bundle() string { tags := "ii/ok" if m.RepTo != "" { tags = "ii/ok/repto/" + m.RepTo } lines := []string{ tags, m.EchoArea, strconv.Itoa(int(m.Date.Unix())), m.From, m.Addr, string(m.MsgTo), m.Subject, "", m.Message, } return strings.Join(lines, "\n") } func (m *Message) PointMessage() string { lines := []string{ m.EchoArea, string(m.MsgTo), m.Subject, "", } if m.RepTo != "" { lines = append(lines, fmt.Sprintf("@repto:%s", m.RepTo)) } lines = append(lines, m.Message) return strings.Join(lines, "\n") }