Go sort slice of pointers
<p>Consider the following:</p>

<pre><code>type Item struct {
    Title      string
    Date       time.Time
}  

type Items []Item

func (slice Items) Len() int {
    return len(slice)
}

func (slice Items) Less(i, j int) bool {
    return slice[i].Date.After(slice[j].Date)
}

func (slice Items) Swap(i, j int) {
    slice[i], slice[j] = slice[j], slice[i]
}
</code></pre>

<p>In the main method, I have a slice of pointers to <code>Item</code>, that must be sorted. My attempt is:</p>

<pre><code>items := make(Items, len(in.Items)) //in.Items is of type []*Item
for i, value := range in.Items {
    items[i] = *value
}

sort.Sort(items)

in.Items = make([]*Item, len(items))
for i, value := range items {
    in.Items[i] = &amp;value
}
</code></pre>

<p>While it does what I need, is there another way to do this?</p>