Browse Source

added initial code

main
gryffyn 2 months ago
parent
commit
af6379f2e6
  1. 1
      .gitignore
  2. 43
      gfn-notify.go
  3. 3
      go.mod

1
.gitignore

@ -0,0 +1 @@
go.sum

43
gfn-notify.go

@ -0,0 +1,43 @@
package gfnnotify
import (
"bytes"
"encoding/json"
"net/http"
"net/url"
)
type Notifier struct {
apptoken string
endpoint string
}
type Msg struct {
Title string `json:"title"`
Message string `json:"message"`
Priority string `json:"priority"`
Extras struct {
ClientDisplay struct {
ContentType string `json:"contentType"`
} `json:"client::display"`
} `json:"extras"`
}
func (m *Notifier) SendMarkdownMsg(msg Msg) (int, error) {
msg.Extras.ClientDisplay.ContentType = "text/markdown"
js, err := json.Marshal(msg)
form, err := http.Post(m.endpoint+"/message?token="+m.apptoken, "application/json", bytes.NewBuffer(js))
defer form.Body.Close()
return form.StatusCode, err
}
func (m *Notifier) SendPlainMsg(msg Msg) (int, error) {
data := url.Values{
"title": {msg.Title},
"message": {msg.Message},
"priority": {msg.Priority},
}
form, err := http.PostForm(m.endpoint+"/message?token="+m.apptoken, data)
defer form.Body.Close()
return form.StatusCode, err
}

3
go.mod

@ -0,0 +1,3 @@
module git.neveris.one/gryffyn/gfn-notify
go 1.16
Loading…
Cancel
Save