This commit is contained in:
fredix 2019-06-09 16:41:58 +02:00
parent c39a2e98b8
commit 9ed74ef1f7
2 changed files with 52 additions and 10 deletions

View file

@ -1,24 +1,42 @@
package main
import (
"fmt"
"encoding/json"
"bytes"
"net/http"
"net/url"
"os"
"log"
)
func main() {
token := os.Getenv("PLUGIN_GOTIFYTOKEN")
endpoint := os.Getenv("PLUGIN_GOTIFYENDPOINT")
title := os.Getenv("PLUGIN_GOTIFYTITLE")
message := os.Getenv("message")
priority := os.Getenv("PLUGIN_GOTIFYPRIORITY")
url := os.Getenv("PLUGIN_GOTIFYENDPOINT") + "/message?token=" + os.Getenv("PLUGIN_GOTIFYTOKEN")
resp, err := http.PostForm(endpoint + "/message?token=" + token, url.Values{"message": {message}, "title": {title}, "priority": {priority}})
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))
if resp != nil {
resp.Body.Close()
}
if err != nil {
log.Fatalln(err)
}
if err != nil {
fmt.Printf("err : ", err)
log.Fatalln(err)
}
}

24
drone-gotify_back.go Normal file
View file

@ -0,0 +1,24 @@
package main
import (
"net/http"
"net/url"
"os"
"log"
)
func main() {
token := os.Getenv("PLUGIN_GOTIFYTOKEN")
endpoint := os.Getenv("PLUGIN_GOTIFYENDPOINT")
title := os.Getenv("PLUGIN_GOTIFYTITLE")
message := os.Getenv("message")
priority := os.Getenv("PLUGIN_GOTIFYPRIORITY")
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 {
log.Fatalln(err)
}
}