From 3c399401a6ec05d5867295c8dc0d7aa57521582d Mon Sep 17 00:00:00 2001 From: Karen <8099322@qq.com> Date: Tue, 8 Aug 2023 09:29:19 +0800 Subject: [PATCH] fix(path.go): change logrus.Fatal to logrus.Fatalf to format error message fix(root.go): add defer f.Close() to ensure file is closed after writing The logrus.Fatal function is changed to logrus.Fatalf in order to format the error message with the error string. This provides more detailed information about the error when logging. In root.go, a defer statement is added to ensure that the file is closed after writing. This prevents resource leaks and ensures proper cleanup. --- cmd/config/path.go | 2 +- cmd/root.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/config/path.go b/cmd/config/path.go index fedbb69..0f79627 100644 --- a/cmd/config/path.go +++ b/cmd/config/path.go @@ -25,7 +25,7 @@ func init() { func userHomeDir() string { usr, err := user.Current() if err != nil { - logrus.Fatal("Could not get user home directory: %s\n", err) + logrus.Fatalf("Could not get user home directory: %s\n", err) } return usr.HomeDir } diff --git a/cmd/root.go b/cmd/root.go index b8a9dcb..6f87f7b 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -32,10 +32,10 @@ scfproxy is a tool that implements multiple proxies based on cloud functions and RunE: func(cmd *cobra.Command, args []string) error { if !fileutil.PathExists(config.ProviderConfigPath) { f, err := os.Create(config.ProviderConfigPath) - defer f.Close() if err != nil { return err } + defer f.Close() if _, err := f.Write([]byte(config.ProviderConfigContent)); err != nil { return err }