beaconfire.go 1019 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package beaconfire
  2. import (
  3. "errors"
  4. "fmt"
  5. "time"
  6. )
  7. var (
  8. ErrNoReceiver = errors.New("no receiver")
  9. )
  10. type BeaconParam struct {
  11. From, Title, Content string
  12. Ts int64
  13. To []string
  14. Fmt string
  15. }
  16. func NewBeaconParam(from, title, content string, fmt string, to ...string) *BeaconParam {
  17. bp := &BeaconParam{
  18. From: from,
  19. Title: title,
  20. Content: content,
  21. Ts: time.Now().Unix(),
  22. Fmt: fmt,
  23. }
  24. bp.To = append(bp.To, to...)
  25. return bp
  26. }
  27. func (bp BeaconParam) FormatMarkdown() string {
  28. return fmt.Sprintf("### %v\n> %v\n> %v\n> %v", bp.Title, bp.From, Ts2Str(bp.Ts), bp.Content)
  29. }
  30. func (bp BeaconParam) FormatHTML() string {
  31. return fmt.Sprintf("<b>%v</b>\n<i>%v</i>\n<i>%v</i>\n%v", bp.Title, bp.From, Ts2Str(bp.Ts), bp.Content)
  32. }
  33. func (bp BeaconParam) FormatPlainText() string {
  34. return fmt.Sprintf("%v\n%v\n%v\n%v", bp.Title, bp.From, Ts2Str(bp.Ts), bp.Content)
  35. }
  36. type BeaconFire interface {
  37. Name() string
  38. Send(*BeaconParam) error
  39. }