Skip to content

Commit

Permalink
Added a const and inverted the if condition
Browse files Browse the repository at this point in the history
  • Loading branch information
rao-aneesh committed Jul 17, 2024
1 parent 63ebf91 commit a0c3068
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const (
configName = ".gnmic"
configLogPrefix = "[config] "
envPrefix = "GNMIC"
trimChars = " \r\n\t"
)

var ErrInvalidConfig = errors.New("invalid configuration")
Expand Down Expand Up @@ -686,13 +687,13 @@ func (c *Config) CreateSetRequest(targetName string) ([]*gnmi.SetRequest, error)
c.logger.Printf("error reading data from file '%s': %v", c.LocalFlags.SetUpdateFile[i], err)
return nil, err
}
trimChars := " \r\n\t"
if c.LocalFlags.SetNoTrim {
trimChars = ""
trim := ""
if !c.LocalFlags.SetNoTrim {
trim = trimChars
}
updOpt = api.Update(
api.Path(strings.TrimSpace(p)),
api.Value(string(bytes.Trim(updateData, trimChars)), c.Encoding),
api.Value(string(bytes.Trim(updateData, trim)), c.Encoding),
)

} else {
Expand All @@ -712,13 +713,13 @@ func (c *Config) CreateSetRequest(targetName string) ([]*gnmi.SetRequest, error)
c.logger.Printf("error reading data from file '%s': %v", c.LocalFlags.SetReplaceFile[i], err)
return nil, err
}
trimChars := " \r\n\t"
if c.LocalFlags.SetNoTrim {
trimChars = ""
trim := ""
if !c.LocalFlags.SetNoTrim {
trim = trimChars
}
replaceOpt = api.Replace(
api.Path(strings.TrimSpace(p)),
api.Value(string(bytes.Trim(replaceData, trimChars)), c.Encoding),
api.Value(string(bytes.Trim(replaceData, trim)), c.Encoding),
)

} else {
Expand All @@ -738,13 +739,13 @@ func (c *Config) CreateSetRequest(targetName string) ([]*gnmi.SetRequest, error)
c.logger.Printf("error reading data from file '%s': %v", c.LocalFlags.SetUnionReplaceFile[i], err)
return nil, err
}
trimChars := " \r\n\t"
if c.LocalFlags.SetNoTrim {
trimChars = ""
trim := ""
if !c.LocalFlags.SetNoTrim {
trim = trimChars
}
unionReplaceOpt = api.UnionReplace(
api.Path(strings.TrimSpace(p)),
api.Value(string(bytes.Trim(replaceData, trimChars)), c.Encoding),
api.Value(string(bytes.Trim(replaceData, trim)), c.Encoding),
)

} else {
Expand Down

0 comments on commit a0c3068

Please sign in to comment.