diff --git a/drone-gotify.go b/drone-gotify.go index ed2c6f5..f45ad14 100644 --- a/drone-gotify.go +++ b/drone-gotify.go @@ -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) + } + } diff --git a/drone-gotify_back.go b/drone-gotify_back.go new file mode 100644 index 0000000..ed2c6f5 --- /dev/null +++ b/drone-gotify_back.go @@ -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) + } +}