use Golang interface methods instead of C++ (pure) virtual functions:
for the The Go Way to this see package sort:
type Interface interface {
// Len is the number of elements in the collection.
Len() int
// Less reports whether the element with
// index i should sort before the element with index j.
Less(i, j int) bool
// Swap swaps the elements with indexes i and j.
Swap(i, j int)
}
and sample (custom sorting with age):
package main
import "fmt"
import "sort"
type Person struct {
name string
age int
}
type PS []Person
// Len is part of sort.Interface.
func (s PS) Len() int {
return len(s)
}
// Swap is part of sort.Interface.
func (s PS) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}
// Less is part of sort.Interface.
func (s PS) Less(i, j int) bool {
return s[i].age < s[j].age
}
func main() {
s := PS{Person{"Alex", 23}, Person{"Jane", 22}}
fmt.Println(s) // [{Alex 23} {Jane 22}]
sort.Sort(s)
fmt.Println(s) // [{Jane 22} {Alex 23}]
}