From 5473fd114d2bf9a10bd886649c12982d189b8f67 Mon Sep 17 00:00:00 2001 From: shirou Date: Wed, 30 Nov 2022 23:17:41 +0000 Subject: [PATCH] [disk][host]: change to use type alias. --- disk/disk_windows.go | 2 ++ host/host_linux.go | 2 ++ host/warnings.go | 30 --------------------------- {disk => internal/common}/warnings.go | 2 +- 4 files changed, 5 insertions(+), 31 deletions(-) delete mode 100644 host/warnings.go rename {disk => internal/common}/warnings.go (96%) diff --git a/disk/disk_windows.go b/disk/disk_windows.go index 3e3d991..6aa47a7 100644 --- a/disk/disk_windows.go +++ b/disk/disk_windows.go @@ -15,6 +15,8 @@ import ( "golang.org/x/sys/windows/registry" ) +type Warnings = common.Warnings + var ( procGetDiskFreeSpaceExW = common.Modkernel32.NewProc("GetDiskFreeSpaceExW") procGetLogicalDriveStringsW = common.Modkernel32.NewProc("GetLogicalDriveStringsW") diff --git a/host/host_linux.go b/host/host_linux.go index 940415c..949baba 100644 --- a/host/host_linux.go +++ b/host/host_linux.go @@ -19,6 +19,8 @@ import ( "golang.org/x/sys/unix" ) +type Warnings = common.Warnings + type lsbStruct struct { ID string Release string diff --git a/host/warnings.go b/host/warnings.go deleted file mode 100644 index 182a293..0000000 --- a/host/warnings.go +++ /dev/null @@ -1,30 +0,0 @@ -package host - -import "fmt" - -type Warnings struct { - List []error - Verbose bool -} - -func (w *Warnings) Add(err error) { - w.List = append(w.List, err) -} - -func (w *Warnings) Reference() error { - if len(w.List) > 0 { - return w - } - return nil -} - -func (w *Warnings) Error() string { - if w.Verbose { - str := "" - for i, e := range w.List { - str += fmt.Sprintf("\tError %d: %s\n", i, e.Error()) - } - return str - } - return fmt.Sprintf("Number of warnings: %v", len(w.List)) -} diff --git a/disk/warnings.go b/internal/common/warnings.go similarity index 96% rename from disk/warnings.go rename to internal/common/warnings.go index ce13aa9..a4aaada 100644 --- a/disk/warnings.go +++ b/internal/common/warnings.go @@ -1,4 +1,4 @@ -package disk +package common import "fmt"