Skip to content

Commit

Permalink
INT - fix sonar code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
jcollins-axway committed Aug 9, 2019
1 parent 3916b5b commit e6b8b81
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions linker/executionContext.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import (
"github.com/Axway/ace-golang-sdk/rpc"
)

const (
stringType = "string"
intType = "int"
boolType = "boolean"
)

// messageContext - Represents the current execution context that holds the message and related properties
type messageContext struct {
ctx context.Context
Expand Down Expand Up @@ -50,15 +56,15 @@ func (msgCtx *messageContext) GetStringConfigValue(name string) string {
if !ok {
log.Warn("The requested configuration did not exist, returning default for type string",
zap.String(logging.LogConfigParamName, name),
zap.String(logging.LogConfigParamTypeRequested, "string"))
zap.String(logging.LogConfigParamTypeRequested, stringType))
return ""
}

if cfgParam.GetType() != "string" {
log.Warn("The requested configuration is not correct type, returning default for type string",
zap.String(logging.LogConfigParamName, name),
zap.String(logging.LogConfigParamType, cfgParam.GetType()),
zap.String(logging.LogConfigParamTypeRequested, "string"))
zap.String(logging.LogConfigParamTypeRequested, stringType))
return ""
}

Expand All @@ -71,15 +77,15 @@ func (msgCtx *messageContext) GetIntConfigValue(name string) int {
if !ok {
log.Warn("The requested configuration did not exist, returning default for type int",
zap.String(logging.LogConfigParamName, name),
zap.String(logging.LogConfigParamTypeRequested, "boolean"))
zap.String(logging.LogConfigParamTypeRequested, boolType))
return 0
}

if cfgParam.GetType() != "int" {
log.Warn("The requested configuration is not correct type, returning default for type int",
zap.String(logging.LogConfigParamName, name),
zap.String(logging.LogConfigParamType, cfgParam.GetType()),
zap.String(logging.LogConfigParamTypeRequested, "int"))
zap.String(logging.LogConfigParamTypeRequested, intType))
return 0
}

Expand All @@ -88,7 +94,7 @@ func (msgCtx *messageContext) GetIntConfigValue(name string) int {
log.Warn("Could not parse the config value to an int, returning default for type int",
zap.String(logging.LogConfigParamName, name),
zap.String(logging.LogConfigParamType, cfgParam.GetType()),
zap.String(logging.LogConfigParamTypeRequested, "int"))
zap.String(logging.LogConfigParamTypeRequested, intType))
return 0
}
return intVal
Expand All @@ -100,15 +106,15 @@ func (msgCtx *messageContext) GetBooleanConfigValue(name string) bool {
if !ok {
log.Warn("The requested configuration did not exist, returning default for type boolean",
zap.String(logging.LogConfigParamName, name),
zap.String(logging.LogConfigParamTypeRequested, "boolean"))
zap.String(logging.LogConfigParamTypeRequested, boolType))
return false
}

if cfgParam.GetType() != "boolean" {
log.Warn("The requested configuration is not correct type, returning default for type boolean",
zap.String(logging.LogConfigParamName, name),
zap.String(logging.LogConfigParamType, cfgParam.GetType()),
zap.String(logging.LogConfigParamTypeRequested, "boolean"))
zap.String(logging.LogConfigParamTypeRequested, boolType))
return false
}

Expand All @@ -117,7 +123,7 @@ func (msgCtx *messageContext) GetBooleanConfigValue(name string) bool {
log.Warn("Could not parse the config value to a boolean, returning default for type boolean",
zap.String(logging.LogConfigParamName, name),
zap.String(logging.LogConfigParamType, cfgParam.GetType()),
zap.String(logging.LogConfigParamTypeRequested, "boolean"))
zap.String(logging.LogConfigParamTypeRequested, boolType))
return false
}
return boolVal
Expand Down

0 comments on commit e6b8b81

Please sign in to comment.