123456789101112131415161718192021222324252627282930313233343536 |
- package bullet
- import (
- "bytes"
- "encoding/json"
- )
- type Push struct {
- Type string `json:"type"`
- Title string `json:"title"`
- Body string `json:"body"`
- Url string `json:"url"`
- }
- //GetReader
- func (p Push) GetReader() (*bytes.Buffer, error) {
- jsonBytes, err := json.Marshal(p)
- if err != nil {
- return nil, err
- }
- buffer := bytes.NewBuffer(jsonBytes)
- return buffer, err
- }
- //NewNotePush
- func NewNotePush(title, text string) Push {
- push := Push{Type: "note", Title: title, Body: text}
- return push
- }
- //NewLinkPush
- func NewLinkPush(title, text, link string) Push {
- push := Push{Type: "note", Title: title, Body: text, Url: link}
- return push
- }
|