drone-gotify/drone-gotify.go
2019-06-09 16:41:58 +02:00

42 lines
814 B
Go

package main
import (
"fmt"
"encoding/json"
"bytes"
"net/http"
"os"
"log"
)
func main() {
url := os.Getenv("PLUGIN_GOTIFYENDPOINT") + "/message?token=" + os.Getenv("PLUGIN_GOTIFYTOKEN")
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 {
fmt.Printf("err : ", err)
log.Fatalln(err)
}
}