type earthMass … type au … type Planet … type By … // Sort is a method on the function type, By, that sorts the argument slice according to the function. func (by By) Sort(planets []Planet) { … } type planetSorter … // Len is part of sort.Interface. func (s *planetSorter) Len() int { … } // Swap is part of sort.Interface. func (s *planetSorter) Swap(i, j int) { … } // Less is part of sort.Interface. It is implemented by calling the "by" closure in the sorter. func (s *planetSorter) Less(i, j int) bool { … } var planets … // ExampleSortKeys demonstrates a technique for sorting a struct type using programmable sort criteria. func Example_sortKeys() { … }