我有一个
[]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