bugfix, output formatting

This commit is contained in:
Erik Eckert 2023-12-21 13:33:17 -07:00
parent af0ea46b8b
commit 40b26c7b8e

View File

@ -42,7 +42,7 @@ func MPE_IsProject(input *Payload) (projectnumber string, project_name string) {
sb.WriteString(value + "|")
} else {
return // return as this must not be a project...
// DoNothing
}
} // end of loop
@ -50,11 +50,20 @@ func MPE_IsProject(input *Payload) (projectnumber string, project_name string) {
project_text := sb.String()
project_slice := strings.Split(project_text, "|")
// first value should be a digit, if not this can't be a project
isProject0, _ := regexp.MatchString(`(^[0-9])`, project_slice[0])
isProject1, _ := regexp.MatchString(`(^[0-9])`, project_slice[1])
isProject2, _ := regexp.MatchString(`(^[0-9])`, project_slice[2])
isProject0, err := regexp.MatchString(`(^[0-9])`, project_slice[0])
if err != nil {
fmt.Printf("err.Error(): %v\n", err.Error())
}
isProject1, err := regexp.MatchString(`(^[0-9])`, project_slice[1])
if err != nil {
fmt.Printf("err.Error(): %v\n", err.Error())
}
isProject2, err := regexp.MatchString(`(^[0-9])`, project_slice[2])
if err != nil {
fmt.Printf("err.Error(): %v\n", err.Error())
}
// isProject, _ = regexp.MatchString(`(^[0-9])`, project_slice[3])
if isProject0 || isProject1 || isProject2 {
if isProject0 && isProject1 && isProject2 {
project_regex, _ := regexp.Compile(`(^[0-9]{1,3})`) // regex to match against
regex_tidy_string, _ := regexp.Compile(`[-_]+|^\s`) //regex to tidy up folder paths
@ -121,6 +130,16 @@ func MPE_ValidateForward(in *Payload) bool {
func readDataStream(resp http.ResponseWriter, request *http.Request) {
// reqBody, _ := io.ReadAll(request.Body)
colorReset := "\033[0m"
// colorRed := "\033[31m"
colorGreen := "\033[32m"
colorYellow := "\033[33m"
colorBlue := "\033[34m"
// colorPurple := "\033[35m"
// colorCyan := "\033[36m"
// colorWhite := "\033[37m"
var log_values log_data
var request_body Payload // init request_body as data type Payload - uses custom structs
body_string, _ := io.ReadAll(request.Body) // ready Body Data
@ -145,16 +164,16 @@ func readDataStream(resp http.ResponseWriter, request *http.Request) {
log_values.EventID = request_body.Data[0].EventID
log_values.EventType = request_body.Data[0].EventType
log_values.User = request_body.Data[0].User.DisplayName
log_values.TargetPath = request_body.Data[0].PathData.TargetPath
log_values.TargetPath = colorGreen + request_body.Data[0].PathData.TargetPath + colorReset
fmt.Printf("%+v\n", log_values) // output log values to stdout - first round
// fmt.Printf("%+v\n", log_values) // output log values to stdout - first round
var MPE_ShouldFoward = MPE_ValidateForward(&request_body)
var MPE_ProjectNumber, MPE_ProjectName = MPE_IsProject(&request_body)
log_values.ExternalShare = MPE_ShouldFoward
log_values.MPE_ProjectName = MPE_ProjectName
log_values.MPE_ProjectNumber = MPE_ProjectNumber
log_values.MPE_ProjectName = colorYellow + MPE_ProjectName + colorReset
log_values.MPE_ProjectNumber = colorBlue + MPE_ProjectNumber + colorReset
fmt.Printf("%+v\n", log_values) // output log values to stdout - second round