Skip to content

Commit

Permalink
use go 1.8 slice sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
HeavyHorst committed Dec 29, 2016
1 parent 7adb8f8 commit 42508e3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 66 deletions.
63 changes: 0 additions & 63 deletions template/sort.go

This file was deleted.

8 changes: 6 additions & 2 deletions template/filter_functions.go → template/template_filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,15 @@ func filterSortByLength(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *
switch values.(type) {
case []string:
v := values.([]string)
sort.Sort(byLength(v))
sort.Slice(v, func(i, j int) bool {
return len(v[i]) < len(v[j])
})
return pongo2.AsValue(v), nil
case memkv.KVPairs:
v := values.(memkv.KVPairs)
sort.Sort(byLengthKV(v))
sort.Slice(v, func(i, j int) bool {
return len(v[i].Key) < len(v[j].Key)
})
return pongo2.AsValue(v), nil
}

Expand Down
File renamed without changes.
7 changes: 6 additions & 1 deletion template/template_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ func lookupSRV(service, proto, name string) []*net.SRV {
if err != nil {
return []*net.SRV{}
}
sort.Sort(sortSRV(addrs))
//sort.Sort(sortSRV(addrs))
sort.Slice(addrs, func(i, j int) bool {
str1 := fmt.Sprintf("%s%d%d%d", addrs[i].Target, addrs[i].Port, addrs[i].Priority, addrs[i].Weight)
str2 := fmt.Sprintf("%s%d%d%d", addrs[j].Target, addrs[j].Port, addrs[j].Priority, addrs[j].Weight)
return str1 < str2
})
return addrs
}

0 comments on commit 42508e3

Please sign in to comment.