From 02d56bbf8cf3f2f84a17fd6bdab131f0e70c76a4 Mon Sep 17 00:00:00 2001 From: Vaibhav Date: Thu, 1 Aug 2024 13:48:40 +0530 Subject: [PATCH] Better function names --- client/client.go | 15 +++++++++++---- .../client_embedded_test_with_schema/main.go | 2 +- .../main.go | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/client/client.go b/client/client.go index 6a8dd08..5770b58 100644 --- a/client/client.go +++ b/client/client.go @@ -600,12 +600,16 @@ func NewClient(url, defaultLogLvl, svcName, svcInstName string, enableSlog bool, } // NewClientWithServer returns a client config which performs the job of the server as well. -// It is a wrapper around NewClientWithServerWithSchema with schema name set to a blank string +// It is a wrapper around NewDirectToDbClientCustomSchemaTable with schema name set to a blank string func NewClientWithServer(dbUrl, defaultLogLvl, svcName, svcInstName string, enableSlog bool) *Config { - return NewClientWithServerWithSchema(dbUrl, "", "", defaultLogLvl, svcName, svcInstName, enableSlog) + return NewDirectToDbClient(dbUrl, defaultLogLvl, svcName, svcInstName, enableSlog) } -// NewClientWithServerWithSchema returns a client config which performs the job of the server as well +func NewDirectToDbClient(dbUrl, defaultLogLvl, svcName, svcInstName string, enableSlog bool) *Config { + return NewDirectToDbClientCustomSchemaTable(dbUrl, "", "", defaultLogLvl, svcName, svcInstName, enableSlog) +} + +// NewDirectToDbClientCustomSchemaTable returns a client config which performs the job of the server as well // It differs from NewClient in two main ways: it does not have the option to do bulk inserts (they are not needed) // and it accepts the database URL instead of server URL. // @@ -615,6 +619,9 @@ func NewClientWithServer(dbUrl, defaultLogLvl, svcName, svcInstName string, enab // The schemaName is the name of the schema (optional) where the postgresql table resides. // If the table is accessible without a schema name using the dbUrl connection, this can be left blank. // +// The tableName is the name of the table where the logs are to be stored. +// This is supposed to be set if your table is named anything other than `app_log`. +// // The defaultLogLvl parameter is the log level for logging. It must be one of the constants // defined in the constants package, such as INFO, WARN, ERROR, etc. If an invalid value // is given, the function will print a warning message and use INFO as the default level. @@ -630,7 +637,7 @@ func NewClientWithServer(dbUrl, defaultLogLvl, svcName, svcInstName string, enab // The enableSlog parameter is a boolean flag that indicates whether to enable slog logging // to standard output. If true, the function will create and assign a new slog.Logger object // to the Config object. If false, the Config object will have a nil Slogger field. -func NewClientWithServerWithSchema(dbUrl, schemaName, tableName, defaultLogLvl, svcName, svcInstName string, enableSlog bool) *Config { +func NewDirectToDbClientCustomSchemaTable(dbUrl, schemaName, tableName, defaultLogLvl, svcName, svcInstName string, enableSlog bool) *Config { if !isValid(defaultLogLvl) { fmt.Printf("L#1M1XXN - %v is not an acceptable log level. %v will be used as the default log level", defaultLogLvl, constants.DefaultLogLevel) defaultLogLvl = constants.DefaultLogLevel diff --git a/cmd/examples/client_embedded_test_with_schema/main.go b/cmd/examples/client_embedded_test_with_schema/main.go index 03c53b7..286f631 100644 --- a/cmd/examples/client_embedded_test_with_schema/main.go +++ b/cmd/examples/client_embedded_test_with_schema/main.go @@ -12,7 +12,7 @@ func main() { fmt.Println("This") return } - log := client.NewClientWithServerWithSchema("postgres://vaibhav:vaibhav@127.0.0.1:5432/bark", "audit", "", "INFO", "brktest", "load test session", false) + log := client.NewDirectToDbClientCustomSchemaTable("postgres://vaibhav:vaibhav@127.0.0.1:5432/bark", "audit", "", "INFO", "brktest", "load test session", false) for i := 0; i < 500; i++ { log.Printf("20JFH1 - schema default message - %v", i) diff --git a/cmd/examples/client_embedded_test_with_schema_and_table_name/main.go b/cmd/examples/client_embedded_test_with_schema_and_table_name/main.go index 6c81324..502d9f0 100644 --- a/cmd/examples/client_embedded_test_with_schema_and_table_name/main.go +++ b/cmd/examples/client_embedded_test_with_schema_and_table_name/main.go @@ -12,7 +12,7 @@ func main() { fmt.Println("This") return } - log := client.NewClientWithServerWithSchema("postgres://vaibhav:vaibhav@127.0.0.1:5432/bark", "audit", "app_log2", "INFO", "brktest", "load test session", false) + log := client.NewDirectToDbClientCustomSchemaTable("postgres://vaibhav:vaibhav@127.0.0.1:5432/bark", "audit", "app_log2", "INFO", "brktest", "load test session", false) for i := 0; i < 500; i++ { log.Printf("I#20XJRQ - schema default message - %v", i)