-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsort.go
More file actions
55 lines (41 loc) · 753 Bytes
/
sort.go
File metadata and controls
55 lines (41 loc) · 753 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package pagorminator
import (
"fmt"
"strings"
)
var (
_ Order = new(Asc)
_ Order = new(Desc)
)
type (
Order interface {
GormString() string
order()
}
Sort []Order
Asc string
Desc string
)
func (a Asc) GormString() string {
return fmt.Sprintf("%s ASC", a)
}
func (a Asc) order() {}
func (d Desc) GormString() string {
return fmt.Sprintf("%s DESC", d)
}
func (d Desc) order() {}
// NewSort Creates sort (slices of [Order]).
func NewSort(orders ...Order) Sort {
return orders
}
// Unsorted no sorting.
func Unsorted() Sort {
return Sort{}
}
func (s Sort) String() string {
orderStrings := make([]string, len(s))
for i, order := range s {
orderStrings[i] = order.GormString()
}
return strings.Join(orderStrings, ", ")
}