Skip to content

Commit

Permalink
INT - Added duplicate check on adding config param
Browse files Browse the repository at this point in the history
  • Loading branch information
vivekschauhan committed Jul 30, 2019
1 parent 7259537 commit 16510f6
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions linker/linker.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,21 @@ func addConfigParam(configParam *rpc.ConfigParameter) {
serviceConfigParamTemplates = append(serviceConfigParamTemplates, configParam)
}

func checkDuplicateConfigParam(name string) error {
for _, cfgParam := range serviceConfigParamTemplates {
if cfgParam.Name == name {
return fmt.Errorf("Duplicate definition for config parameter : %s", name)
}
}
return nil
}

// AddStringConfigParam - Add String config parameter for the service
func AddStringConfigParam(name, defaultValue string, required bool) error {
err := checkDuplicateConfigParam(name)
if err != nil {
return err
}
stringConfigParam := &rpc.ConfigParameter{
Name: name,
Type: "string",
Expand All @@ -90,6 +103,10 @@ func AddStringConfigParam(name, defaultValue string, required bool) error {

// AddIntConfigParam - Add integer config parameter for the service
func AddIntConfigParam(name string, defaultValue int, required bool) error {
err := checkDuplicateConfigParam(name)
if err != nil {
return err
}
intConfigParam := &rpc.ConfigParameter{
Name: name,
Type: "int",
Expand All @@ -102,6 +119,10 @@ func AddIntConfigParam(name string, defaultValue int, required bool) error {

// AddBooleanConfigParam - Add boolean config parameter for the service
func AddBooleanConfigParam(name string, defaultValue bool) error {
err := checkDuplicateConfigParam(name)
if err != nil {
return err
}
boolConfigParam := &rpc.ConfigParameter{
Name: name,
Type: "boolean",
Expand Down

0 comments on commit 16510f6

Please sign in to comment.