From e71815cf03ba9dbad11977d4b8d22f7687725d2f Mon Sep 17 00:00:00 2001 From: guoguangwu Date: Thu, 8 Jun 2023 12:08:48 +0800 Subject: [PATCH] chore: fmt modify --- core/config/json/json.go | 4 ++-- core/config/xml/xml.go | 4 ++-- core/logs/es/es.go | 2 +- server/web/config.go | 4 ++-- task/task_test.go | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/core/config/json/json.go b/core/config/json/json.go index 098f0308..36ab6a75 100644 --- a/core/config/json/json.go +++ b/core/config/json/json.go @@ -99,12 +99,12 @@ func (c *JSONConfigContainer) sub(key string) (map[string]interface{}, error) { } value, ok := c.data[key] if !ok { - return nil, errors.New(fmt.Sprintf("key is not found: %s", key)) + return nil, fmt.Errorf("key is not found: %s", key) } res, ok := value.(map[string]interface{}) if !ok { - return nil, errors.New(fmt.Sprintf("the type of value is invalid, key: %s", key)) + return nil, fmt.Errorf("the type of value is invalid, key: %s", key) } return res, nil } diff --git a/core/config/xml/xml.go b/core/config/xml/xml.go index 1d7494b4..cd9d4e00 100644 --- a/core/config/xml/xml.go +++ b/core/config/xml/xml.go @@ -120,11 +120,11 @@ func (c *ConfigContainer) sub(key string) (map[string]interface{}, error) { } value, ok := c.data[key] if !ok { - return nil, errors.New(fmt.Sprintf("the key is not found: %s", key)) + return nil, fmt.Errorf("the key is not found: %s", key) } res, ok := value.(map[string]interface{}) if !ok { - return nil, errors.New(fmt.Sprintf("the value of this key is not a structure: %s", key)) + return nil, fmt.Errorf("the value of this key is not a structure: %s", key) } return res, nil } diff --git a/core/logs/es/es.go b/core/logs/es/es.go index a07ee83c..d1ba452d 100644 --- a/core/logs/es/es.go +++ b/core/logs/es/es.go @@ -81,7 +81,7 @@ func (el *esLogger) Init(config string) error { if len(el.Formatter) > 0 { fmtr, ok := logs.GetFormatter(el.Formatter) if !ok { - return errors.New(fmt.Sprintf("the formatter with name: %s not found", el.Formatter)) + return fmt.Errorf("the formatter with name: %s not found", el.Formatter) } el.formatter = fmtr } diff --git a/server/web/config.go b/server/web/config.go index 006201a6..5207ee89 100644 --- a/server/web/config.go +++ b/server/web/config.go @@ -505,7 +505,7 @@ func defaultRecoverPanic(ctx *context.Context, cfg *Config) { break } logs.Critical(fmt.Sprintf("%s:%d", file, line)) - stack = stack + fmt.Sprintln(fmt.Sprintf("%s:%d", file, line)) + stack = stack + fmt.Sprintf("%s:%d\n", file, line) } if ctx.Output.Status != 0 { @@ -629,7 +629,7 @@ func assignConfig(ac config.Configer) error { for adaptor, cfg := range BConfig.Log.Outputs { err := logs.SetLogger(adaptor, cfg) if err != nil { - fmt.Fprintln(os.Stderr, fmt.Sprintf("%s with the config %q got err:%s", adaptor, cfg, err.Error())) + fmt.Fprintf(os.Stderr, "%s with the config %q got err:%s\n", adaptor, cfg, err.Error()) return err } } diff --git a/task/task_test.go b/task/task_test.go index 1fdfd4b9..98a3a059 100644 --- a/task/task_test.go +++ b/task/task_test.go @@ -147,7 +147,7 @@ func TestTask_Run(t *testing.T) { task := func(ctx context.Context) error { cnt++ fmt.Printf("Hello, world! %d \n", cnt) - return errors.New(fmt.Sprintf("Hello, world! %d", cnt)) + return fmt.Errorf("Hello, world! %d", cnt) } tk := NewTask("taska", "0/30 * * * * *", task) for i := 0; i < 200; i++ {