push.go 654 B

123456789101112131415161718192021222324252627282930313233
  1. package bullet
  2. import (
  3. "bytes"
  4. "encoding/json"
  5. )
  6. type pushStruct struct {
  7. Type string `json:"type"`
  8. Title string `json:"title"`
  9. Body string `json:"body"`
  10. Url string `json:"url"`
  11. }
  12. func (p pushStruct) getReader() (*bytes.Buffer, error) {
  13. jsonBytes, err := json.Marshal(p)
  14. if err != nil {
  15. return nil, err
  16. }
  17. buffer := bytes.NewBuffer(jsonBytes)
  18. return buffer, err
  19. }
  20. func newNotePush(title, text string) pushStruct {
  21. push := pushStruct{Type: "note", Title: title, Body: text}
  22. return push
  23. }
  24. func newLinkPush(title, text, link string) pushStruct {
  25. push := pushStruct{Type: "note", Title: title, Body: text, Url: link}
  26. return push
  27. }