-
Notifications
You must be signed in to change notification settings - Fork 18
/
utils.go
39 lines (33 loc) · 909 Bytes
/
utils.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
37
38
39
package common
import (
"reflect"
"strings"
"github.com/mandelsoft/filepath/pkg/filepath"
"github.com/modern-go/reflect2"
"github.com/opencontainers/go-digest"
)
// DigestToFileName returns the file name for a digest.
func DigestToFileName(digest digest.Digest) string {
return strings.Replace(digest.String(), ":", ".", 1)
}
// PathToDigest retuurns the digest encoded into a file name.
func PathToDigest(path string) digest.Digest {
n := filepath.Base(path)
idx := strings.LastIndex(n, ".")
if idx < 0 {
return ""
}
return digest.Digest(n[:idx] + ":" + n[idx+1:])
}
////////////////////////////////////////////////////////////////////////////////
func IterfaceSlice(slice interface{}) []interface{} {
if reflect2.IsNil(slice) {
return nil
}
v := reflect.ValueOf(slice)
r := make([]interface{}, v.Len())
for i := 0; i < v.Len(); i++ {
r[i] = v.Index(i).Interface()
}
return r
}