From 68fc3218aac0f99ede51de44c0f2d90247b5c04b Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Wed, 21 Aug 2024 14:09:32 -0400 Subject: [PATCH 1/2] params: avoid deprecated ioutil.ReadDir ioutil.ReadDir was deprecated in Go 1.16, and the lint workflow has started to flag it. The suggested replacement is os.ReadDir, which returns a list of fs.DirEntry. For this spot, the downstream code expects a list of fs.FileInfo, so add the wrapper suggested in the Go docs. --- cmd/params.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/cmd/params.go b/cmd/params.go index 456c4f08..6c43ee68 100644 --- a/cmd/params.go +++ b/cmd/params.go @@ -16,7 +16,8 @@ package cmd import ( "fmt" - "io/ioutil" + "io/fs" + "os" "path/filepath" "runtime" "sort" @@ -221,13 +222,30 @@ func sortParams(params []string) []string { return sorted } +func readDir(dirname string) ([]fs.FileInfo, error) { + entries, err := os.ReadDir(dirname) + if err != nil { + return nil, err + } + infos := make([]fs.FileInfo, 0, len(entries)) + for _, entry := range entries { + info, err := entry.Info() + if err != nil { + return infos, err + } + infos = append(infos, info) + } + + return infos, nil +} + func params(cmd *cobra.Command, args []string) { if debug { viper.Debug() } var modelDirs []string if dir != "" { - fi, err := ioutil.ReadDir(dir) + fi, err := readDir(dir) if err != nil { log.Fatal(err) } From 0c79738656ecef727104a29316a4a3a5bb93a1d8 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Wed, 21 Aug 2024 14:59:51 -0400 Subject: [PATCH 2/2] root: silence staticcheck note about deprecated rand.Seed The latest lint CI run failed with SA1019: rand.Seed has been deprecated since Go 1.20 and an alternative has been available since Go 1.0: As of Go 1.20 there is no reason to call Seed with a random value. [...] So once our minimum Go version is 1.20.0, we can remove the rand.Seed() call. --- cmd/root.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/root.go b/cmd/root.go index 982346f7..2127cfbb 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -72,7 +72,8 @@ func NewRootCmd() *cobra.Command { } // Set random for application - rand.Seed(time.Now().UnixNano()) + // TODO: Remove Seed call once minimum Go is 1.20 (SA1019). + rand.Seed(time.Now().UnixNano()) //nolint:staticcheck cobra.OnInitialize(initConfig)