У меня есть []byte
, который мне нужно отсортировать в порядке возрастания.
Я получаю объект с элементами, а затем перебираю массив для создания возвращаемого объекта:
// unfortunately, for some obscure reason I can't change the data types of the caller and the object from the function call are different, although both are []byte underneath (...)
type ID []byte
// in another package:
type ByteInterface []byte
func (c *Store) GetAll() ByteInterface {
returnObj := make([]ByteInterface,0)
obj, err := GetData()
// err handling
for _, b := range obj.IDs {
returnObj = append(returnObj, ByteInterface(b))
}
return returnObj
}
Поэтому я спрашиваю себя, можно ли сделать append
, чтобы returnObj
сортировался сразу, или мне нужно отсортировать obj.ByteData
заранее (или отсортировать returnOjb
впоследствии).