first commit
This commit is contained in:
51
cloudlog/cloudlog.go
Normal file
51
cloudlog/cloudlog.go
Normal file
@ -0,0 +1,51 @@
|
||||
package cloudlog
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"git.rouggy.com/CloudlogUDP/config"
|
||||
"git.rouggy.com/CloudlogUDP/qso"
|
||||
)
|
||||
|
||||
type CloudlogAPIString struct {
|
||||
Key string `json:"key"`
|
||||
StationProfileID string `json:"station_profile_id"`
|
||||
Type string `json:"type"`
|
||||
QSOData string `json:"string"`
|
||||
}
|
||||
|
||||
func SendCloudlogMsg(qso qso.QSO, config config.Config) {
|
||||
QSODataJson := qso.Call + qso.Band + qso.Mode + qso.Freq + qso.QSODate + qso.TimeOn + qso.RSTR + qso.RSTS + qso.GridSquare
|
||||
|
||||
jsonStr := CloudlogAPIString{
|
||||
Key: config.CloudLog.API,
|
||||
StationProfileID: "1",
|
||||
Type: "adif",
|
||||
QSOData: QSODataJson,
|
||||
}
|
||||
|
||||
b, err := json.Marshal(jsonStr)
|
||||
if err != nil {
|
||||
fmt.Println("error:", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("POST", config.CloudLog.QSOUrl, bytes.NewBuffer(b))
|
||||
req.Header.Set("X-Custom-Header", "myvalue")
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
// body, _ := io.ReadAll(resp.Body)
|
||||
// fmt.Println("response Body:", string(body))
|
||||
|
||||
fmt.Printf("QSO Details:\nCall: %v\nBand: %v\nFreq: %v\n", qso.Call, qso.Band, qso.Freq)
|
||||
fmt.Println("QSO Uploaded to Cloudlog")
|
||||
}
|
Reference in New Issue
Block a user