github.com/mhilton/juju-juju@v0.0.0-20150901100907-a94dd2c73455/storage/sort.go (about) 1 // Copyright 2014 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package storage 5 6 import "sort" 7 8 // SortBlockDevices sorts block devices by device name. 9 func SortBlockDevices(devices []BlockDevice) { 10 sort.Sort(byDeviceName(devices)) 11 } 12 13 type byDeviceName []BlockDevice 14 15 func (b byDeviceName) Len() int { 16 return len(b) 17 } 18 19 func (b byDeviceName) Swap(i, j int) { 20 b[i], b[j] = b[j], b[i] 21 } 22 23 func (b byDeviceName) Less(i, j int) bool { 24 return b[i].DeviceName < b[j].DeviceName 25 }