1
0
Fork 0
mirror of https://github.com/postmannen/ctrl.git synced 2024-12-14 12:37:31 +00:00

changed message.Data from []string to []byte

This commit is contained in:
postmannen 2022-01-31 08:49:46 +01:00
parent 73db37beba
commit 1fa45b1293
6 changed files with 32 additions and 43 deletions

View file

@ -81,7 +81,7 @@ func (e *errorKernel) start(ringBufferBulkInCh chan<- []subjectAndMessage) error
ToNode: "errorCentral",
FromNode: errEvent.process.node,
FileName: "error.log",
Data: []string{er},
Data: []byte(er),
Method: REQErrorLog,
ACKTimeout: errEvent.process.configuration.ErrorMessageTimeout,
Retries: errEvent.process.configuration.ErrorMessageRetries,

View file

@ -21,7 +21,7 @@ type Message struct {
// specify the cli commands to execute on a node, and this is
// also the field where we put the returned data in a reply
// message.
Data []string `json:"data" yaml:"data"`
Data []byte `json:"data" yaml:"data"`
// Method, what request type to use, like REQCliCommand, REQHttpGet..
Method Method `json:"method" yaml:"method"`
// Additional arguments that might be needed when executing the

View file

@ -235,7 +235,7 @@ func (s startup) pubREQHello(p process) {
Directory: "hello-messages",
ToNode: Node(p.configuration.CentralNodeName),
FromNode: Node(p.node),
Data: []string{d},
Data: []byte(d),
Method: REQHello,
ACKTimeout: 10,
Retries: 1,

View file

@ -319,7 +319,7 @@ func newReplyMessage(proc process, message Message, outData []byte) {
newMsg := Message{
ToNode: message.FromNode,
FromNode: message.ToNode,
Data: []string{string(outData)},
Data: outData,
Method: message.ReplyMethod,
MethodArgs: message.ReplyMethodArgs,
MethodTimeout: message.ReplyMethodTimeout,
@ -621,14 +621,12 @@ func (m methodREQToFileAppend) handler(proc process, message Message, node strin
}
defer f.Close()
for _, d := range message.Data {
_, err := f.Write([]byte(d))
f.Sync()
if err != nil {
er := fmt.Errorf("error: methodEventTextLogging.handler: failed to write to file : %v, %v", file, err)
proc.processes.errorKernel.errSend(proc, message, er)
log.Printf("%v\n", er)
}
_, err = f.Write(message.Data)
f.Sync()
if err != nil {
er := fmt.Errorf("error: methodEventTextLogging.handler: failed to write to file : %v, %v", file, err)
proc.processes.errorKernel.errSend(proc, message, er)
log.Printf("%v\n", er)
}
ackMsg := []byte("confirmed from: " + node + ": " + fmt.Sprint(message.ID))
@ -678,14 +676,12 @@ func (m methodREQToFile) handler(proc process, message Message, node string) ([]
}
defer f.Close()
for _, d := range message.Data {
_, err := f.Write([]byte(d))
f.Sync()
if err != nil {
er := fmt.Errorf("error: methodEventTextLogging.handler: failed to write to file: file: %v, %v", file, err)
proc.processes.errorKernel.errSend(proc, message, er)
log.Printf("%v\n", er)
}
_, err = f.Write(message.Data)
f.Sync()
if err != nil {
er := fmt.Errorf("error: methodEventTextLogging.handler: failed to write to file: file: %v, %v", file, err)
proc.processes.errorKernel.errSend(proc, message, er)
log.Printf("%v\n", er)
}
ackMsg := []byte("confirmed from: " + node + ": " + fmt.Sprint(message.ID))
@ -759,7 +755,7 @@ func (m methodREQCopyFileFrom) handler(proc process, message Message, node strin
msg.ToNode = Node(DstNode)
//msg.Method = REQToFile
msg.Method = REQCopyFileTo
msg.Data = []string{string(out)}
msg.Data = out
msg.Directory = dstDir
msg.FileName = dstFile
@ -901,13 +897,11 @@ func (m methodREQCopyFileTo) handler(proc process, message Message, node string)
}
defer f.Close()
for _, d := range message.Data {
_, err := f.Write([]byte(d))
f.Sync()
if err != nil {
er := fmt.Errorf("failed to write to file: file: %v, error: %v", file, err)
errCh <- er
}
_, err = f.Write(message.Data)
f.Sync()
if err != nil {
er := fmt.Errorf("failed to write to file: file: %v, error: %v", file, err)
errCh <- er
}
// All went ok, send a signal to the outer select statement.
@ -1031,12 +1025,10 @@ func (m methodREQErrorLog) handler(proc process, message Message, node string) (
}
defer f.Close()
for _, d := range message.Data {
_, err := f.Write([]byte(d))
f.Sync()
if err != nil {
log.Printf("error: methodEventTextLogging.handler: failed to write to file: %v\n", err)
}
_, err = f.Write(message.Data)
f.Sync()
if err != nil {
log.Printf("error: methodEventTextLogging.handler: failed to write to file: %v\n", err)
}
ackMsg := []byte("confirmed from: " + node + ": " + fmt.Sprint(message.ID))
@ -1223,7 +1215,7 @@ func (m methodREQCliCommand) handler(proc process, message Message, node string)
// Put all the data which is a slice of string into a single
// string so we can put it in a single env variable.
envData = strings.Join(message.Data, "")
envData = string(message.Data)
}
}
@ -1303,10 +1295,7 @@ func (m methodREQToConsole) handler(proc process, message Message, node string)
log.Printf("error: no tui client started\n")
}
default:
for _, v := range message.Data {
fmt.Fprintf(os.Stdout, "%v", v)
}
fmt.Fprintf(os.Stdout, "%v", string(message.Data))
fmt.Println()
}
@ -1773,7 +1762,7 @@ func (m methodREQRelayInitial) handler(proc process, message Message, node strin
message.ToNode = Node(relayTo)
message.FromNode = Node(node)
message.Method = REQRelay
message.Data = []string{string(out)}
message.Data = out
sam, err := newSubjectAndMessage(message)
if err != nil {

View file

@ -332,7 +332,7 @@ func createErrorMsgContent(conf *Configuration, FromNode Node, theError error) s
ToNode: "errorCentral",
FromNode: FromNode,
FileName: "error.log",
Data: []string{er},
Data: []byte(er),
Method: REQErrorLog,
ACKTimeout: conf.ErrorMessageTimeout,
Retries: conf.ErrorMessageRetries,

4
tui.go
View file

@ -27,7 +27,7 @@ import (
// tui holds general types used within the tui.
type tui struct {
toConsoleCh chan []string
toConsoleCh chan []byte
toRingbufferCh chan []subjectAndMessage
ctx context.Context
nodeName Node
@ -35,7 +35,7 @@ type tui struct {
// newTui returns a new tui.
func newTui(nodeName Node) (*tui, error) {
ch := make(chan []string)
ch := make(chan []byte)
s := tui{
toConsoleCh: ch,
nodeName: nodeName,