Skip to content

Commit 8dd8c1c

Browse files
fixed up some return statements and flow control for fetching a devfile.
1 parent d5aba7a commit 8dd8c1c

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

index/server/pkg/server/endpoint.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,17 @@ func serveDevfileStarterProject(c *gin.Context) {
146146
var index []indexSchema.Schema
147147
bytes, err := ioutil.ReadFile(indexPath)
148148
if err != nil {
149-
return nil, err
149+
return bytes, err
150150
}
151151
err = json.Unmarshal(bytes, &index)
152152
if err != nil {
153-
return nil, err
153+
return make([]byte, 0), err
154154
}
155155

156+
// Reuse 'bytes' for devfile bytes
157+
bytes = make([]byte, 0)
156158
for _, devfileIndex := range index {
157159
if devfileIndex.Name == devfileName {
158-
var bytes []byte
159160
if devfileIndex.Type == indexSchema.StackDevfileType {
160161
bytes, err = pullStackFromRegistry(devfileIndex)
161162
} else {
@@ -166,11 +167,11 @@ func serveDevfileStarterProject(c *gin.Context) {
166167
}
167168
}
168169

169-
return bytes, err
170+
break
170171
}
171172
}
172173

173-
return nil, nil
174+
return bytes, err
174175
}(devfileName)
175176
if err != nil {
176177
log.Print(err.Error())
@@ -195,7 +196,7 @@ func serveDevfileStarterProject(c *gin.Context) {
195196
// "error": err.Error(),
196197
// "status": fmt.Sprintf("failed to pull the devfile of %s", devfileName),
197198
// })
198-
// return nil
199+
// return make([]byte, 0)
199200
// }
200201
// err = json.Unmarshal(bytes, &index)
201202
// if err != nil {
@@ -204,8 +205,11 @@ func serveDevfileStarterProject(c *gin.Context) {
204205
// "error": err.Error(),
205206
// "status": fmt.Sprintf("failed to pull the devfile of %s", devfileName),
206207
// })
207-
// return nil
208+
// return make([]byte, 0)
208209
// }
210+
//
211+
// // Reuse 'bytes' for devfile bytes
212+
// bytes = make([]byte, 0)
209213
// for _, devfileIndex := range index {
210214
// if devfileIndex.Name == devfileName {
211215
// var bytes []byte
@@ -224,7 +228,7 @@ func serveDevfileStarterProject(c *gin.Context) {
224228
// "error": err.Error(),
225229
// "status": fmt.Sprintf("failed to pull the devfile of %s", devfileName),
226230
// })
227-
// return nil
231+
// return make([]byte, 0)
228232
// }
229233

230234
// return bytes
@@ -235,7 +239,7 @@ func serveDevfileStarterProject(c *gin.Context) {
235239
// "status": fmt.Sprintf("the devfile of %s didn't exist", devfileName),
236240
// })
237241

238-
// return nil
242+
// return bytes
239243
// }(c, devfileName)
240244

241245
/****/

0 commit comments

Comments
 (0)