This commit is contained in:
fredix 2019-06-09 17:05:46 +02:00
parent 44158debc4
commit a31d1b63c9

View file

@ -1,42 +1,24 @@
package main
import (
"fmt"
"encoding/json"
"bytes"
"net/http"
"net/url"
"os"
"log"
)
func main() {
url := os.Getenv("PLUGIN_GOTIFYENDPOINT") + "/message?token=" + os.Getenv("PLUGIN_GOTIFYTOKEN")
token := os.Getenv("PLUGIN_GOTIFYTOKEN")
endpoint := os.Getenv("PLUGIN_GOTIFYENDPOINT")
title := os.Getenv("PLUGIN_GOTIFYTITLE")
message := os.Getenv("message")
priority := os.Getenv("PLUGIN_GOTIFYPRIORITY")
msg := struct {
Title string `json:"title"`
Message string `json:"message"`
Priority string `json:"priority"`
}{
Title: os.Getenv("PLUGIN_GOTIFYTITLE"),
Message: os.Getenv("message"),
Priority: os.Getenv("PLUGIN_GOTIFYPRIORITY"),
}
raw, err := json.Marshal(msg)
if err != nil {
log.Fatalln(err)
}
//fmt.Printf("json : ", bytes.NewReader(raw))
//os.Stdout.Write(raw)
resp, err := http.Post(url, "application/json", bytes.NewReader(raw))
resp, err := http.PostForm(endpoint + "/message?token=" + token, url.Values{"message": {message}, "title": {title}, "priority": {priority}})
if resp != nil {
resp.Body.Close()
}
if err != nil {
fmt.Printf("err : ", err)
log.Fatalln(err)
}
if err != nil {
log.Fatalln(err)
}
}