beaconfire.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package beaconfire
  2. import (
  3. "errors"
  4. "fmt"
  5. )
  6. const (
  7. BEACON_FMT_HTML = "html"
  8. BEACON_FMT_MARKDOWN = "markdown"
  9. BEACON_FMT_PLAIN = "plain"
  10. )
  11. var (
  12. ErrNoReceiver = errors.New("no receiver")
  13. )
  14. type BeaconMessage struct {
  15. Title string // Message Title
  16. Content string // Message Content
  17. Ts int64 //..
  18. Fmt string
  19. }
  20. func NewBeaconMessage(title, content string, ts int64, fmt string) *BeaconMessage {
  21. bp := &BeaconMessage{
  22. Title: title,
  23. Content: content,
  24. Ts: ts,
  25. Fmt: fmt,
  26. }
  27. return bp
  28. }
  29. func (bp BeaconMessage) FormatMarkdown() string {
  30. return fmt.Sprintf("### %v\n> %v\n> %v", bp.Title, Ts2Str(bp.Ts), bp.Content)
  31. }
  32. func (bp BeaconMessage) FormatHTML() string {
  33. return fmt.Sprintf("<b>%v</b>\n<i>%v</i>\n%v", bp.Title, Ts2Str(bp.Ts), bp.Content)
  34. }
  35. func (bp BeaconMessage) FormatPlainText() string {
  36. return fmt.Sprintf("%v\n%v\n%v", bp.Title, Ts2Str(bp.Ts), bp.Content)
  37. }
  38. // Interface of BeaconFire
  39. type BeaconFire interface {
  40. Name() string
  41. Send(*BeaconMessage) error
  42. }