diff options
Diffstat (limited to 'sd_id128')
-rw-r--r-- | sd_id128/get.go | 9 | ||||
-rw-r--r-- | sd_id128/util.go | 15 |
2 files changed, 5 insertions, 19 deletions
diff --git a/sd_id128/get.go b/sd_id128/get.go index d8cdcfa..40d1219 100644 --- a/sd_id128/get.go +++ b/sd_id128/get.go @@ -17,6 +17,7 @@ package sd_id128 import ( "crypto/rand" "os" + "io/ioutil" "strings" ) @@ -61,11 +62,11 @@ var cachedMachineID ID128 // machine-id(5): https://www.freedesktop.org/software/systemd/man/machine-id.html func GetMachineID() (ID128, error) { if cachedMachineID == (ID128{}) { - str, err := readfile("/etc/machine-id") + str, err := ioutil.ReadFile("/etc/machine-id") if err != nil { return ID128{}, err } - id, err := ParsePlain(strings.TrimSuffix(str, "\n")) + id, err := ParsePlain(strings.TrimSuffix(string(str), "\n")) if err != nil { return ID128{}, err } @@ -94,11 +95,11 @@ var cachedBootID ID128 // random(4): http://man7.org/linux/man-pages/man4/random.4.html func GetBootUUID() (ID128, error) { if cachedBootID == (ID128{}) { - str, err := readfile("/proc/sys/kernel/random/boot_id") + str, err := ioutil.ReadFile("/proc/sys/kernel/random/boot_id") if err != nil { return ID128{}, err } - id, err := ParseUUID(strings.TrimSuffix(str, "\n")) + id, err := ParseUUID(strings.TrimSuffix(string(str), "\n")) if err != nil { return ID128{}, err } diff --git a/sd_id128/util.go b/sd_id128/util.go index ae50008..77c6079 100644 --- a/sd_id128/util.go +++ b/sd_id128/util.go @@ -14,11 +14,6 @@ package sd_id128 -import ( - "io/ioutil" - "os" -) - func hexchar(x byte) byte { return "0123456789abcdef"[x&15] } @@ -33,13 +28,3 @@ func unhexchar(c byte) (byte, error) { } return 0, ErrInvalid } - -func readfile(filename string) (string, error) { - file, err := os.Open(filename) - if err != nil { - return "", err - } - defer file.Close() - b, err := ioutil.ReadAll(file) - return string(b), err -} |