diff --git a/client_configuration.go b/client_configuration.go index 03c70b6c0..ea6a637b2 100644 --- a/client_configuration.go +++ b/client_configuration.go @@ -27,8 +27,8 @@ type ClientConfig struct { // ClientConfigCommonProps properties from "common" section type ClientConfigCommonProps struct { - LogLevel *string `json:"log_level"` - LogPath *string `json:"log_path"` + LogLevel string `json:"log_level,omitempty"` + LogPath string `json:"log_path,omitempty"` } func parseClientConfiguration(filePath string) (*ClientConfig, error) { @@ -62,13 +62,13 @@ func validateClientConfiguration(clientConfig *ClientConfig) error { if clientConfig.Common == nil { return errors.New("common section in client config not found") } - return validateLogLevel(clientConfig) + return validateLogLevel(*clientConfig) } -func validateLogLevel(clientConfig *ClientConfig) error { +func validateLogLevel(clientConfig ClientConfig) error { var logLevel = clientConfig.Common.LogLevel - if logLevel != nil && *logLevel != "" { - _, error := toLogLevel(*logLevel) + if logLevel != "" { + _, error := toLogLevel(logLevel) if error != nil { return error } @@ -76,12 +76,12 @@ func validateLogLevel(clientConfig *ClientConfig) error { return nil } -func toLogLevel(logLevelString string) (*string, error) { +func toLogLevel(logLevelString string) (string, error) { var logLevel = strings.ToUpper(logLevelString) switch logLevel { case Off, Error, Warn, Info, Debug, Trace: - return &logLevel, nil + return logLevel, nil default: - return nil, errors.New("unknown log level: " + logLevelString) + return "", errors.New("unknown log level: " + logLevelString) } } diff --git a/client_configuration_test.go b/client_configuration_test.go index 85fcba7b0..bf8004f29 100644 --- a/client_configuration_test.go +++ b/client_configuration_test.go @@ -17,8 +17,8 @@ func TestParseConfiguration(t *testing.T) { Name string FileName string FileContents string - ExpectedLogLevel *string - ExpectedLogPath *string + ExpectedLogLevel string + ExpectedLogPath string }{ { Name: "TestWithLogLevelUpperCase", @@ -29,8 +29,8 @@ func TestParseConfiguration(t *testing.T) { "log_path" : "/some-path/some-directory" } }`, - ExpectedLogLevel: toStringPointer("INFO"), - ExpectedLogPath: toStringPointer("/some-path/some-directory"), + ExpectedLogLevel: "INFO", + ExpectedLogPath: "/some-path/some-directory", }, { Name: "TestWithLogLevelLowerCase", @@ -41,8 +41,8 @@ func TestParseConfiguration(t *testing.T) { "log_path" : "/some-path/some-directory" } }`, - ExpectedLogLevel: toStringPointer("info"), - ExpectedLogPath: toStringPointer("/some-path/some-directory"), + ExpectedLogLevel: "info", + ExpectedLogPath: "/some-path/some-directory", }, { Name: "TestWithMissingValues", @@ -50,8 +50,8 @@ func TestParseConfiguration(t *testing.T) { FileContents: `{ "common": {} }`, - ExpectedLogLevel: nil, - ExpectedLogPath: nil, + ExpectedLogLevel: "", + ExpectedLogPath: "", }, } for _, tc := range testCases { @@ -84,7 +84,7 @@ func TestParseAllLogLevels(t *testing.T) { assert := assert.New(t) assert.Equal(nil, err, "Error should be nil") - assert.Equal(logLevel, *config.Common.LogLevel, "Log level should be as expected") + assert.Equal(logLevel, config.Common.LogLevel, "Log level should be as expected") }) } } @@ -155,11 +155,6 @@ func TestParseConfigurationFails(t *testing.T) { } } -func toStringPointer(value string) *string { - var copyOfValue = value - return ©OfValue -} - func CreateFile(t *testing.T, fileName string, fileContents string, directory string) string { fullFileName := path.Join(directory, fileName) writeErr := os.WriteFile(fullFileName, []byte(fileContents), 0644)