初始化项目

This commit is contained in:
zeaslity
2025-03-27 16:09:20 +08:00
parent e09a32d1e8
commit fc2d585489
709 changed files with 516391 additions and 0 deletions

View File

@@ -0,0 +1,79 @@
package pusher
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"wdd.io/agent-common/logger"
)
var log = logger.Log
// CmiiUpdateMessage message_pusher/cmii/CmiiMessage.go
type CmiiUpdateMessage struct {
Namespace string
AppName string
FromTag string
ToTag string
Replicas string
DeployStatus bool
}
type Message struct { // TODO combine with server.message
ID string
Event string
Time int64
Topic string
Message string
Title string
Priority int
Tags []string
Click string
Icon string
// Additional fields
TopicURL string
SubscriptionID string
Raw string
}
func (c *CmiiUpdateMessage) SendMessage() (message Message) {
// 将结构体转换为JSON字符串
requestBytes, err := json.Marshal(c)
if err != nil {
fmt.Println("Error encoding request body to JSON:", err)
return
}
url := "http://192.168.35.71:8080/cmii/update" // 替换为实际的API地址
req, err := http.NewRequest("POST", url, bytes.NewBuffer(requestBytes))
if err != nil {
fmt.Println("Error creating request:", err)
return
}
// 添加请求头
req.Header.Set("Content-Type", "application/json")
// 发送请求并获取响应
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("Error sending request:", err)
}
defer resp.Body.Close()
bodyBytes, _ := io.ReadAll(resp.Body)
var m Message
err = json.Unmarshal(bodyBytes, &m)
if err != nil {
log.ErrorF("Error unmarshaling response body to JSON: %s", err.Error())
return message
}
return m
}

View File

@@ -0,0 +1,21 @@
package pusher
import (
"testing"
"wdd.io/agent-common/utils"
)
func TestCmiiUpdateMessage_SendMessage(t *testing.T) {
c := &CmiiUpdateMessage{
Namespace: "dev",
AppName: "cmii-uav-gateway",
FromTag: "5.1.0",
ToTag: "5.5.0",
Replicas: "2",
DeployStatus: false,
}
utils.BeautifulPrint(c)
c.SendMessage()
}