CobraV2/monitor/parse/parse.go
foglar 90bde3740b data parser in monitor app
- created code format for sent data
- created parser for data
- go.mod and go.sum added
2024-02-05 13:46:50 +01:00

33 lines
720 B
Go

package parse
import (
"log"
"strconv"
"strings"
)
func Parser(s string) map[int]string {
// TODO: check if line isn't comment
// improve reading data
lines := strings.Split(s, "\n")
data_structure := make(map[int]string)
for _, line := range lines {
// find $ and * in text and get value between them
startIndex := strings.Index(line, "$")
endIndex := strings.Index(line, "*")
if startIndex != -1 && endIndex != -1 {
value := line[startIndex+1 : endIndex]
data := strings.Split(strings.TrimSpace(value), ";")
ident, err := strconv.Atoi(strings.TrimSpace(data[0]))
if err != nil {
log.Print(err)
}
info := data[1]
data_structure[ident] = info
}
}
return data_structure
}