CloudlogUDP/qrzcom/qrzcom.go

54 lines
1.1 KiB
Go
Raw Permalink Normal View History

2023-11-29 11:02:30 +07:00
package qrzcom
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"net/url"
"git.rouggy.com/CloudlogUDP/config"
"git.rouggy.com/CloudlogUDP/qso"
)
type QRZComAPIString struct {
Key string `json:"KEY"`
Action string `json:"ACTION"`
Adif string `json:"ADIF"`
}
func SendQRZcomlogMsg(qso qso.QSO, config config.Config) {
QSODataJson := qso.Call + qso.Band + qso.Mode + qso.Freq + qso.QSODate + qso.TimeOn + qso.RSTR + qso.RSTS + qso.StationCallsign + "<eor>"
jsonStr := QRZComAPIString{
Key: config.QRZ.API,
Action: "INSERT",
Adif: QSODataJson,
}
b, err := json.Marshal(jsonStr)
if err != nil {
fmt.Println("error:", err)
}
params := url.Values{}
params.Add("KEY", jsonStr.Key)
params.Add("ACTION", "INSERT")
params.Add("ADIF", jsonStr.Adif)
urlQRZ := fmt.Sprint("https://logbook.qrz.com/api?" + params.Encode())
req, err := http.NewRequest("POST", urlQRZ, bytes.NewBuffer(b))
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
fmt.Println("QSO Uploaded to QRZ.com")
}