Skip to content

Commit

Permalink
Reduce code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
tmiddlet2666 committed Nov 6, 2024
1 parent 5d7d097 commit 4b12aff
Showing 1 changed file with 22 additions and 34 deletions.
56 changes: 22 additions & 34 deletions pkg/cmd/formatting.go
Original file line number Diff line number Diff line change
Expand Up @@ -2041,28 +2041,32 @@ func FormatProxyServers(services []config.ProxySummary, protocol string) string
// common values
table.AddRow(value.NodeID, value.HostIP, value.ServiceName)

if protocol == tcp {
table.AddColumnsToRow(formatLargeInteger(value.ConnectionCount),
formattingFunction(value.TotalBytesSent), formattingFunction(value.TotalBytesReceived))
if OutputFormat == constants.WIDE {
table.AddColumnsToRow(formatLargeInteger(value.TotalMessagesSent),
formatLargeInteger(value.TotalMessagesReceived), formatLargeInteger(value.OutgoingByteBacklog),
formatLargeInteger(value.OutgoingMessageBacklog), formatLargeInteger(value.UnAuthConnectionAttempts))
}
} else {
table.AddColumnsToRow(value.HTTPServerType,
formatLargeInteger(value.TotalRequestCount), formatLargeInteger(value.TotalErrorCount))
if OutputFormat == constants.WIDE {
table.AddColumnsToRow(formatLargeInteger(value.ResponseCount1xx),
formatLargeInteger(value.ResponseCount2xx), formatLargeInteger(value.ResponseCount3xx),
formatLargeInteger(value.ResponseCount4xx), formatLargeInteger(value.ResponseCount5xx))
}
}
addColumns(table, value, protocol, formattingFunction)
}

return table.String()
}

func addColumns(table FormattedTable, value config.ProxySummary, protocol string, formattingFunction func(bytesValue int64) string) {
if protocol == tcp {
table.AddColumnsToRow(formatLargeInteger(value.ConnectionCount),
formattingFunction(value.TotalBytesSent), formattingFunction(value.TotalBytesReceived))
if OutputFormat == constants.WIDE {
table.AddColumnsToRow(formatLargeInteger(value.TotalMessagesSent),
formatLargeInteger(value.TotalMessagesReceived), formatLargeInteger(value.OutgoingByteBacklog),
formatLargeInteger(value.OutgoingMessageBacklog), formatLargeInteger(value.UnAuthConnectionAttempts))
}
} else {
table.AddColumnsToRow(value.HTTPServerType,
formatLargeInteger(value.TotalRequestCount), formatLargeInteger(value.TotalErrorCount))
if OutputFormat == constants.WIDE {
table.AddColumnsToRow(formatLargeInteger(value.ResponseCount1xx),
formatLargeInteger(value.ResponseCount2xx), formatLargeInteger(value.ResponseCount3xx),
formatLargeInteger(value.ResponseCount4xx), formatLargeInteger(value.ResponseCount5xx))
}
}
}

// FormatProxyServersSummary returns the proxy servers' summary information in a column formatted output
// protocol is either tcp or http and will display a different format based upon this.
func FormatProxyServersSummary(services []config.ProxySummary, protocol string) string {
Expand Down Expand Up @@ -2114,23 +2118,7 @@ func FormatProxyServersSummary(services []config.ProxySummary, protocol string)
}
table.AddRow(value.ServiceName)

if protocol == tcp {
table.AddColumnsToRow(formatLargeInteger(value.ConnectionCount),
formattingFunction(value.TotalBytesSent), formattingFunction(value.TotalBytesReceived))
if OutputFormat == constants.WIDE {
table.AddColumnsToRow(formatLargeInteger(value.TotalMessagesSent),
formatLargeInteger(value.TotalMessagesReceived), formatLargeInteger(value.OutgoingByteBacklog),
formatLargeInteger(value.OutgoingMessageBacklog), formatLargeInteger(value.UnAuthConnectionAttempts))
}
} else {
table.AddColumnsToRow(value.HTTPServerType,
formatLargeInteger(value.TotalRequestCount), formatLargeInteger(value.TotalErrorCount))
if OutputFormat == constants.WIDE {
table.AddColumnsToRow(formatLargeInteger(value.ResponseCount1xx),
formatLargeInteger(value.ResponseCount2xx), formatLargeInteger(value.ResponseCount3xx),
formatLargeInteger(value.ResponseCount4xx), formatLargeInteger(value.ResponseCount5xx))
}
}
addColumns(table, value, protocol, formattingFunction)
}

return table.String()
Expand Down

0 comments on commit 4b12aff

Please sign in to comment.