Skip to content

Commit

Permalink
Feedback
Browse files Browse the repository at this point in the history
* Simplify if else
* Make ParseServiceTags private
  • Loading branch information
IamTheFij committed Sep 11, 2023
1 parent 80f214b commit d759c96
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions internal/provider/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ func ValidateImage(image string, metadata, labels map[string]string, watchByDef
case key == "diun.regopt":
img.RegOpt = value
case key == "diun.watch_repo":
var watchRepo bool
if watchRepo, err = strconv.ParseBool(value); err != nil {
if watchRepo, err := strconv.ParseBool(value); err == nil {
img.WatchRepo = &watchRepo
} else {
return img, fmt.Errorf("cannot parse %q value of label %s: %w", value, key, ErrInvalidLabel)
}
img.WatchRepo = &watchRepo
case key == "diun.notify_on":
if len(value) == 0 {
break
Expand Down
6 changes: 3 additions & 3 deletions internal/provider/nomad/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
nomad "github.com/hashicorp/nomad/api"
)

func ParseServiceTags(tags []string) map[string]string {
func parseServiceTags(tags []string) map[string]string {
labels := map[string]string{}

for _, tag := range tags {
Expand Down Expand Up @@ -61,7 +61,7 @@ func (c *Client) listTaskImages() []model.Image {
groupLabels = provider.UpdateMap(groupLabels, taskGroup.Meta)

for _, service := range taskGroup.Services {
groupLabels = provider.UpdateMap(groupLabels, ParseServiceTags(service.Tags))
groupLabels = provider.UpdateMap(groupLabels, parseServiceTags(service.Tags))
}

for _, task := range taskGroup.Tasks {
Expand All @@ -84,7 +84,7 @@ func (c *Client) listTaskImages() []model.Image {
labels := map[string]string{}
labels = provider.UpdateMap(labels, groupLabels)
for _, service := range task.Services {
labels = provider.UpdateMap(labels, ParseServiceTags(service.Tags))
labels = provider.UpdateMap(labels, parseServiceTags(service.Tags))
}

// Finally, merge task meta values
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/nomad/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestParseServiceTags(t *testing.T) {
for _, tt := range testCases {
tt := tt
t.Run(tt.input[0], func(t *testing.T) {
result := ParseServiceTags(tt.input)
result := parseServiceTags(tt.input)
assert.Equal(t, tt.expected, result)
})
}
Expand Down

0 comments on commit d759c96

Please sign in to comment.