Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 925cb18

Browse files
author
Faris Huskovic
committed
make return values more consistent
1 parent 7d89f9e commit 925cb18

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

coder-sdk/image.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,10 @@ func (c Client) ImportImage(ctx context.Context, orgID string, req ImportImageRe
4848
return &img, nil
4949
}
5050

51-
// GetOrganizationImages returns all of the images imported for org.
52-
func (c Client) GetOrganizationImages(ctx context.Context, org string) ([]*Image, error) {
53-
var imgs []*Image
54-
55-
if err := c.requestBody(ctx, http.MethodGet, "/api/orgs/"+org+"/images", nil, &imgs); err != nil {
51+
// GetOrganizationImages returns all of the images imported for orgID.
52+
func (c Client) GetOrganizationImages(ctx context.Context, orgID string) ([]Image, error) {
53+
var imgs []Image
54+
if err := c.requestBody(ctx, http.MethodGet, "/api/orgs/"+orgID+"/images", nil, &imgs); err != nil {
5655
return nil, err
5756
}
5857
return imgs, nil

internal/cmd/ceapi.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ func findImg(ctx context.Context, client *coder.Client, email, imgName string) (
109109

110110
return nil, xerrors.New("please refine your search")
111111
}
112-
return userImgs[0], nil
112+
return &userImgs[0], nil
113113
}
114114

115-
func getImgs(ctx context.Context, client *coder.Client, userEmail string) ([]*coder.Image, error) {
115+
func getImgs(ctx context.Context, client *coder.Client, userEmail string) ([]coder.Image, error) {
116116
u, err := client.UserByEmail(ctx, userEmail)
117117
if err != nil {
118118
return nil, err
@@ -124,7 +124,7 @@ func getImgs(ctx context.Context, client *coder.Client, userEmail string) ([]*co
124124
}
125125

126126
orgs = lookupUserOrgs(u, orgs)
127-
var importedImgs []*coder.Image
127+
var importedImgs []coder.Image
128128

129129
// Get all of the imported images for all of the orgs the user belongs to.
130130
for _, org := range orgs {
@@ -138,7 +138,7 @@ func getImgs(ctx context.Context, client *coder.Client, userEmail string) ([]*co
138138
}
139139

140140
// returns all images that contain imgName as a substring and have been imported by the user.
141-
func lookupUserImgs(ctx context.Context, client *coder.Client, email, imgName string) ([]*coder.Image, error) {
141+
func lookupUserImgs(ctx context.Context, client *coder.Client, email, imgName string) ([]coder.Image, error) {
142142
switch {
143143
case client == nil:
144144
return nil, xerrors.New("nil client")
@@ -154,7 +154,7 @@ func lookupUserImgs(ctx context.Context, client *coder.Client, email, imgName st
154154
return nil, err
155155
}
156156

157-
var userImgs []*coder.Image
157+
var userImgs []coder.Image
158158

159159
// The user may provide an image thats not an exact match
160160
// to one of their imported images but they may be close.
@@ -167,7 +167,7 @@ func lookupUserImgs(ctx context.Context, client *coder.Client, email, imgName st
167167
// If it's an exact match we can overwrite the slice and exit the loop
168168
// since we won't need the fuzzy matched images anymore.
169169
if img.Repository == imgName {
170-
userImgs = []*coder.Image{img}
170+
userImgs = []coder.Image{img}
171171
break
172172
}
173173
}

0 commit comments

Comments
 (0)