beaconfire.go 837 B

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