Skip to content

Commit

Permalink
Refactor string representation methods for 'Priority'
Browse files Browse the repository at this point in the history
The 'FacilityStringFromPrio' and 'SeverityStringFromPrio' methods are refactored to match the 'fmt.Stringer' interface. This makes the code more idiomatic and reduces the need for specific switch cases to handle different scenarios, thus paving the way for improved code maintainability.
  • Loading branch information
wneessen committed Dec 22, 2023
1 parent 7db0203 commit b143e75
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions priority.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,17 @@ func SeverityFromPrio(p Priority) Severity {

// FacilityStringFromPrio returns a string representation of the Facility of a given Priority
func FacilityStringFromPrio(p Priority) string {
switch FacilityFromPrio(p) {
return FacilityFromPrio(p).String()
}

// SeverityStringFromPrio returns a string representation of the Severity of a given Priority
func SeverityStringFromPrio(p Priority) string {
return SeverityFromPrio(p).String()
}

// String satisfies the fmt.Stringer interface for the Facility type
func (f Facility) String() string {
switch f {
case 0:
return "KERN"
case 1:
Expand Down Expand Up @@ -122,9 +132,9 @@ func FacilityStringFromPrio(p Priority) string {
}
}

// SeverityStringFromPrio returns a string representation of the Severity of a given Priority
func SeverityStringFromPrio(p Priority) string {
switch SeverityFromPrio(p) {
// String satisfies the fmt.Stringer interface for the Severity type
func (s Severity) String() string {
switch s {
case 0:
return "EMERGENCY"
case 1:
Expand Down

0 comments on commit b143e75

Please sign in to comment.