forked from thecodeteam/libstorage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
47 lines (42 loc) · 1007 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
40
41
42
43
44
45
46
47
package utils
import (
"fmt"
"io/ioutil"
"os"
"reflect"
"time"
_ "github.com/akutz/golf"
"github.com/emccode/libstorage/api/types"
)
// GetTypePkgPathAndName gets ths type and package path of the provided
// instance.
func GetTypePkgPathAndName(i interface{}) string {
t := reflect.TypeOf(i)
if t.Kind() == reflect.Ptr || t.Kind() == reflect.Interface {
t = t.Elem()
}
pkgPath := t.PkgPath()
typeName := t.Name()
if pkgPath == "" {
return typeName
}
return fmt.Sprintf("%s.%s", pkgPath, typeName)
}
// GetTempSockFile returns a new sock file in a temp space.
func GetTempSockFile() string {
f, err := ioutil.TempFile(types.Run.String(), "")
if err != nil {
panic(err)
}
name := f.Name()
os.RemoveAll(name)
return fmt.Sprintf("%s.sock", name)
}
// DeviceAttachTimeout gets the configured device attach timeout.
func DeviceAttachTimeout(val string) time.Duration {
dur, err := time.ParseDuration(val)
if err != nil {
return time.Duration(30) * time.Second
}
return dur
}