package main import ( "bytes" "encoding/json" "fmt" "net/http" ) type GotifyMessage struct { Title string `json:"title"` Message string `json:"message"` Priority int `json:"priority"` } func Gotify(spot FlexSpot) { if Cfg.Gotify.Enable { message := fmt.Sprintf("DX: %s\nFrom: %s\nFreq: %s\nMode: %s\n", spot.DX, spot.Source, spot.FrequencyMhz, spot.Mode) gotifyMsg := GotifyMessage{ Title: "", Message: message, Priority: 10, } if spot.NewDXCC && Cfg.Gotify.NewDXCC { title := "FlexDXCluster New DXCC" gotifyMsg.Title = title gotifyMsg.Message = message sendToGotify(gotifyMsg) } if spot.NewBand && spot.NewMode && Cfg.Gotify.NewBandAndMode { title := "FlexDXCluster New Mode & Band" gotifyMsg.Title = title gotifyMsg.Message = message sendToGotify(gotifyMsg) } if spot.NewMode && Cfg.Gotify.NewMode && !spot.NewBand { title := "FlexDXCluster New Mode" gotifyMsg.Title = title gotifyMsg.Message = message sendToGotify(gotifyMsg) } if spot.NewBand && Cfg.Gotify.NewBand && !spot.NewMode { title := "FlexDXCluster New Band" gotifyMsg.Title = title gotifyMsg.Message = message sendToGotify(gotifyMsg) } } } func sendToGotify(mess GotifyMessage) { jsonData, err := json.Marshal(mess) if err != nil { Log.Errorln("Error marshaling JSON:", err) return } req, err := http.NewRequest("POST", Cfg.Gotify.URL, bytes.NewBuffer(jsonData)) if err != nil { Log.Errorln("Error creating request:", err) return } req.Header.Set("Content-Type", "application/json") req.Header.Add("Authorization", "Bearer "+Cfg.Gotify.Token) client := &http.Client{} resp, err := client.Do(req) if err != nil { Log.Errorln("Error sending request:", err) return } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { Log.Errorln("Gotify server returned non-OK status:", resp.Status) } else { Log.Debugln("Push successfully sent to Gotify") } }