dont export types (golint)

This commit is contained in:
Noah Zoschke
2018-01-26 09:35:38 -08:00
parent ee20cfb543
commit ee5400dc9f
2 changed files with 11 additions and 11 deletions

View File

@@ -13,7 +13,7 @@ import "fmt"
// corresponding type. Here we've created a `ByLength`
// type that is just an alias for the builtin `[]string`
// type.
type ByLength []string
type byLength []string
// We implement `sort.Interface` - `Len`, `Less`, and
// `Swap` - on our type so we can use the `sort` package's
@@ -22,22 +22,22 @@ type ByLength []string
// hold the actual custom sorting logic. In our case we
// want to sort in order of increasing string length, so
// we use `len(s[i])` and `len(s[j])` here.
func (s ByLength) Len() int {
func (s byLength) Len() int {
return len(s)
}
func (s ByLength) Swap(i, j int) {
func (s byLength) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}
func (s ByLength) Less(i, j int) bool {
func (s byLength) Less(i, j int) bool {
return len(s[i]) < len(s[j])
}
// With all of this in place, we can now implement our
// custom sort by casting the original `fruits` slice to
// `ByLength`, and then use `sort.Sort` on that typed
// `byLength`, and then use `sort.Sort` on that typed
// slice.
func main() {
fruits := []string{"peach", "banana", "kiwi"}
sort.Sort(ByLength(fruits))
sort.Sort(byLength(fruits))
fmt.Println(fruits)
}