Refactor sorting a bit
This commit is contained in:
		
							parent
							
								
									2493e581ae
								
							
						
					
					
						commit
						8dea3f83bc
					
				| @ -67,8 +67,31 @@ func NewSortConfig() qEntrySortConfig { | |||||||
| 	return qEntrySortConfig{} | 	return qEntrySortConfig{} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (c qEntrySortConfig) By(field string, order string) qEntrySortConfig { | func isQEntryAttribute(attributeName string) bool { | ||||||
| 	newAttributeConfig := qEntryAttributeSortConfig{attribute: field, order: order} | 	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) | 	c.attributes = append(c.attributes, newAttributeConfig) | ||||||
| 	return c | 	return c | ||||||
| } | } | ||||||
| @ -77,6 +100,7 @@ func (queue MailQ) Sort(config qEntrySortConfig) { | |||||||
| 	if len(config.attributes) == 0 { | 	if len(config.attributes) == 0 { | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
|  | 	fmt.Printf("SortConfig: %q\n", config) | ||||||
| 	sort.Slice(queue.Entries, func(a int, b int) bool { | 	sort.Slice(queue.Entries, func(a int, b int) bool { | ||||||
| 		for _, sortBy := range config.attributes { | 		for _, sortBy := range config.attributes { | ||||||
| 			var cmp bool | 			var cmp bool | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user