Files
ProjectOctopus/agent-go/config/OctopusMessage.go
2023-03-27 16:06:33 +08:00

51 lines
1.3 KiB
Go

package config
import (
"agent-go/utils"
"encoding/json"
"fmt"
"time"
)
type OctopusMessage struct {
UUID string `json:"uuid"`
InitTime time.Time `json:"init_time" format:"2023-03-21 16:38:30"`
Type string `json:"type"`
Content interface{} `json:"content"`
Result interface{} `json:"result"`
ACTime time.Time `json:"ac_time" format:"2023-03-21 16:38:30"`
}
type ExecutionMessage struct {
NeedResultReplay bool `json:"needResultReplay"`
DurationTask bool `json:"durationTask,default:false"`
Type string `json:"type"`
SingleLineCommand []string `json:"singleLineCommand"`
MultiLineCommand [][]string `json:"multiLineCommand"`
PipeLineCommand [][]string `json:"pipeLineCommand"`
ResultKey string `json:"resultKey"`
}
// BuildOctopusMsg 生成OctopusMessage
func (m *OctopusMessage) BuildOctopusMsg(omType string, content interface{}) *OctopusMessage {
// 当前时间
curTimeString := utils.CurTimeString()
// must write to string format, otherwise it's very hard to deserialize
bytes, err := json.Marshal(content)
if err != nil {
fmt.Sprintf("OctopusMessage Build Error ! %v", err)
}
return &OctopusMessage{
UUID: curTimeString,
InitTime: time.Now(),
Type: omType,
Content: string(bytes),
Result: nil,
ACTime: time.Time{},
}
}