Skip to content

Commit

Permalink
style(pkg/common): improve code readability and maintainability
Browse files Browse the repository at this point in the history
Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com>
  • Loading branch information
cubxxw committed Mar 22, 2023
1 parent 9f84736 commit 208da0d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ifeq ($(OS),Windows_NT)
SHELL:=cmd.exe

# Need BLANK due to makefile parsing of `\`
# (see: <https://stackoverflow.com/questions/54733231/how-to-escape-a-backslash-in-the-end-to-mean-literal-backslash-in-makefile/54733416#54733416>)
# (see: https://stackoverflow.com/questions/54733231/how-to-escape-a-backslash-in-the-end-to-mean-literal-backslash-in-makefile/54733416#54733416)
BLANK:=

# Define variable named `/` to represent OS path separator (usable as `$/` in this file)
Expand Down
10 changes: 3 additions & 7 deletions pkg/client/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (c *Client) parseTagReference(imageName string) (name.Reference, error) {
return nil, errors.New("image is a required parameter")
}
if _, err := name.ParseReference(imageName, name.WeakValidation); err != nil {
return nil, err
return nil, fmt.Errorf("'%s' is not a valid tag reference: %s", imageName, err)
}
ref, err := name.NewTag(imageName, name.WeakValidation)
if err != nil {
Expand Down Expand Up @@ -108,17 +108,13 @@ func contains(slc []string, v string) bool {
}

func getBestRunMirror(registry string, runImage string, mirrors []string, preferredMirrors []string) string {
var runImageList []string
runImageList = append(runImageList, preferredMirrors...)
runImageList = append(runImageList, runImage)
runImageList = append(runImageList, mirrors...)

runImageList := append(append(append([]string{}, preferredMirrors...), runImage), mirrors...)
for _, img := range runImageList {
ref, err := name.ParseReference(img, name.WeakValidation)
if err != nil {
continue
}
if ref.Context().RegistryStr() == registry {
if reg := ref.Context().RegistryStr(); reg == registry {
return img
}
}
Expand Down

0 comments on commit 208da0d

Please sign in to comment.