mirror of
https://framagit.org/fredix/drone-gotify
synced 2026-01-23 02:14:06 +00:00
42 lines
814 B
Go
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)
|
|
}
|
|
|
|
}
|