From bf8afc96e4fd0857a3778a35508e931156d7da1e Mon Sep 17 00:00:00 2001 From: John Guo Date: Sat, 27 Nov 2021 11:53:05 +0800 Subject: [PATCH] improve instance creating of database for package gins --- frame/gins/gins_database.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/frame/gins/gins_database.go b/frame/gins/gins_database.go index e807188fc..f1507d2ac 100644 --- a/frame/gins/gins_database.go +++ b/frame/gins/gins_database.go @@ -60,20 +60,21 @@ func Database(name ...string) gdb.DB { configFilePath string ) if fileConfig, ok := Config().GetAdapter().(*gcfg.AdapterFile); ok { - if configFilePath, err = fileConfig.GetFilePath(); configFilePath == "" { - exampleFileName := "config.example.toml" - if exampleConfigFilePath, _ := fileConfig.GetFilePath(exampleFileName); exampleConfigFilePath != "" { - err = gerror.WrapCodef( + if configFilePath, _ = fileConfig.GetFilePath(); configFilePath == "" { + var ( + exampleFileName = "config.example.toml" + exampleConfigFilePath string + ) + if exampleConfigFilePath, _ = fileConfig.GetFilePath(exampleFileName); exampleConfigFilePath != "" { + err = gerror.NewCodef( gcode.CodeMissingConfiguration, - err, `configuration file "%s" not found, but found "%s", did you miss renaming the example configuration file?`, fileConfig.GetFileName(), exampleFileName, ) } else { - err = gerror.WrapCodef( + err = gerror.NewCodef( gcode.CodeMissingConfiguration, - err, `configuration file "%s" not found, did you miss the configuration file or the misspell the configuration file name?`, fileConfig.GetFileName(), ) @@ -85,9 +86,8 @@ func Database(name ...string) gdb.DB { } // Panic if nothing found in Config object or in gdb configuration. if len(configMap) == 0 && !gdb.IsConfigured() { - err = gerror.WrapCodef( + err = gerror.NewCodef( gcode.CodeMissingConfiguration, - err, `database initialization failed: "%s" node not found, is configuration file or configuration node missing?`, configNodeNameDatabase, )