Refactor sorting a bit
This commit is contained in:
parent
2493e581ae
commit
8dea3f83bc
|
@ -67,8 +67,31 @@ func NewSortConfig() qEntrySortConfig {
|
|||
return qEntrySortConfig{}
|
||||
}
|
||||
|
||||
func (c qEntrySortConfig) By(field string, order string) qEntrySortConfig {
|
||||
newAttributeConfig := qEntryAttributeSortConfig{attribute: field, order: order}
|
||||
func isQEntryAttribute(attributeName string) bool {
|
||||
var isValidAttribute bool
|
||||
switch attributeName {
|
||||
case "Id":
|
||||
case "Status":
|
||||
case "Date":
|
||||
case "Size":
|
||||
case "Sender":
|
||||
case "Recipients":
|
||||
case "Reason":
|
||||
isValidAttribute = true
|
||||
default:
|
||||
isValidAttribute = false
|
||||
}
|
||||
return isValidAttribute
|
||||
}
|
||||
|
||||
func (c qEntrySortConfig) By(attributeName string, order string) qEntrySortConfig {
|
||||
if !isQEntryAttribute(attributeName) {
|
||||
panic(fmt.Sprintf("Invalid sort attribute: '%s' given!", attributeName))
|
||||
}
|
||||
if order != "ASC" && order != "DESC" {
|
||||
panic(fmt.Sprintf("Invalid sort order '%s' given!", order))
|
||||
}
|
||||
newAttributeConfig := qEntryAttributeSortConfig{attribute: attributeName, order: order}
|
||||
c.attributes = append(c.attributes, newAttributeConfig)
|
||||
return c
|
||||
}
|
||||
|
@ -77,6 +100,7 @@ func (queue MailQ) Sort(config qEntrySortConfig) {
|
|||
if len(config.attributes) == 0 {
|
||||
return
|
||||
}
|
||||
fmt.Printf("SortConfig: %q\n", config)
|
||||
sort.Slice(queue.Entries, func(a int, b int) bool {
|
||||
for _, sortBy := range config.attributes {
|
||||
var cmp bool
|
||||
|
|
Loading…
Reference in New Issue