@@ -146,16 +146,17 @@ func serveDevfileStarterProject(c *gin.Context) {
146
146
var index []indexSchema.Schema
147
147
bytes , err := ioutil .ReadFile (indexPath )
148
148
if err != nil {
149
- return nil , err
149
+ return bytes , err
150
150
}
151
151
err = json .Unmarshal (bytes , & index )
152
152
if err != nil {
153
- return nil , err
153
+ return make ([] byte , 0 ) , err
154
154
}
155
155
156
+ // Reuse 'bytes' for devfile bytes
157
+ bytes = make ([]byte , 0 )
156
158
for _ , devfileIndex := range index {
157
159
if devfileIndex .Name == devfileName {
158
- var bytes []byte
159
160
if devfileIndex .Type == indexSchema .StackDevfileType {
160
161
bytes , err = pullStackFromRegistry (devfileIndex )
161
162
} else {
@@ -166,11 +167,11 @@ func serveDevfileStarterProject(c *gin.Context) {
166
167
}
167
168
}
168
169
169
- return bytes , err
170
+ break
170
171
}
171
172
}
172
173
173
- return nil , nil
174
+ return bytes , err
174
175
}(devfileName )
175
176
if err != nil {
176
177
log .Print (err .Error ())
@@ -195,7 +196,7 @@ func serveDevfileStarterProject(c *gin.Context) {
195
196
// "error": err.Error(),
196
197
// "status": fmt.Sprintf("failed to pull the devfile of %s", devfileName),
197
198
// })
198
- // return nil
199
+ // return make([]byte, 0)
199
200
// }
200
201
// err = json.Unmarshal(bytes, &index)
201
202
// if err != nil {
@@ -204,8 +205,11 @@ func serveDevfileStarterProject(c *gin.Context) {
204
205
// "error": err.Error(),
205
206
// "status": fmt.Sprintf("failed to pull the devfile of %s", devfileName),
206
207
// })
207
- // return nil
208
+ // return make([]byte, 0)
208
209
// }
210
+ //
211
+ // // Reuse 'bytes' for devfile bytes
212
+ // bytes = make([]byte, 0)
209
213
// for _, devfileIndex := range index {
210
214
// if devfileIndex.Name == devfileName {
211
215
// var bytes []byte
@@ -224,7 +228,7 @@ func serveDevfileStarterProject(c *gin.Context) {
224
228
// "error": err.Error(),
225
229
// "status": fmt.Sprintf("failed to pull the devfile of %s", devfileName),
226
230
// })
227
- // return nil
231
+ // return make([]byte, 0)
228
232
// }
229
233
230
234
// return bytes
@@ -235,7 +239,7 @@ func serveDevfileStarterProject(c *gin.Context) {
235
239
// "status": fmt.Sprintf("the devfile of %s didn't exist", devfileName),
236
240
// })
237
241
238
- // return nil
242
+ // return bytes
239
243
// }(c, devfileName)
240
244
241
245
/****/
0 commit comments