-
Notifications
You must be signed in to change notification settings - Fork 17
/
arrays.go
36 lines (32 loc) · 879 Bytes
/
arrays.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package tools
import (
"errors"
"fmt"
"reflect"
)
//selete slice
func DeleteSlice(slice interface{}, index int) (interface{}, error) {
sliceValue := reflect.ValueOf(slice)
length := sliceValue.Len()
if slice == nil || length == 0 || (length-1) < index {
return nil, errors.New("error")
}
if length-1 == index {
return sliceValue.Slice(0, index).Interface(), nil
} else if (length - 1) >= index {
return reflect.AppendSlice(sliceValue.Slice(0, index), sliceValue.Slice(index+1, length)).Interface(), nil
}
return nil, errors.New("error")
}
//Convert byte array to hex string .
func BytesToHexString(data []byte) []string {
ret := []string{}
for _, byteData := range data {
ret = append(ret, fmt.Sprintf("%X", byteData))
}
return ret
}
//Convert string to hex string
func StringToHexString(str string) []string {
return BytesToHexString([]byte(str))
}