Skip to content

Commit

Permalink
draft proposal function source added.
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-valdron committed Feb 7, 2022
1 parent 6b44b81 commit 7b8e5ac
Showing 1 changed file with 99 additions and 0 deletions.
99 changes: 99 additions & 0 deletions index/server/pkg/server/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,105 @@ func serveDevfile(c *gin.Context) {
func serveDevfileStarterProject(c *gin.Context) {
devfileName := c.Param("devfileName")
starterProjectName := c.Param("starterProjectName")

/** source from serveDevfile **/
devfileBytes, err := func(devfileName string) ([]byte, error) {
var index []indexSchema.Schema
bytes, err := ioutil.ReadFile(indexPath)
if err != nil {
return nil, err
}
err = json.Unmarshal(bytes, &index)
if err != nil {
return nil, err
}

for _, devfileIndex := range index {
if devfileIndex.Name == devfileName {
var bytes []byte
if devfileIndex.Type == indexSchema.StackDevfileType {
bytes, err = pullStackFromRegistry(devfileIndex)
} else {
// Retrieve the sample devfile stored under /registry/samples/<devfile>
sampleDevfilePath := path.Join(samplesPath, devfileIndex.Name, devfileName)
if _, err = os.Stat(sampleDevfilePath); err == nil {
bytes, err = ioutil.ReadFile(sampleDevfilePath)
}
}

return bytes, err
}
}

return nil, nil
}(devfileName)
if err != nil {
log.Print(err.Error())
c.JSON(http.StatusInternalServerError, gin.H{
"error": err.Error(),
"status": fmt.Sprintf("failed to pull the devfile of %s", devfileName),
})
return
} else if err == nil && devfileBytes == nil {
c.JSON(http.StatusNotFound, gin.H{
"status": fmt.Sprintf("the devfile of %s didn't exist", devfileName),
})
return
}

// devfileBytes := func(c *gin.Context, devfileName string) []byte {
// var index []indexSchema.Schema
// bytes, err := ioutil.ReadFile(indexPath)
// if err != nil {
// log.Print(err.Error())
// c.JSON(http.StatusInternalServerError, gin.H{
// "error": err.Error(),
// "status": fmt.Sprintf("failed to pull the devfile of %s", devfileName),
// })
// return nil
// }
// err = json.Unmarshal(bytes, &index)
// if err != nil {
// log.Print(err.Error())
// c.JSON(http.StatusInternalServerError, gin.H{
// "error": err.Error(),
// "status": fmt.Sprintf("failed to pull the devfile of %s", devfileName),
// })
// return nil
// }
// for _, devfileIndex := range index {
// if devfileIndex.Name == devfileName {
// var bytes []byte
// if devfileIndex.Type == indexSchema.StackDevfileType {
// bytes, err = pullStackFromRegistry(devfileIndex)
// } else {
// // Retrieve the sample devfile stored under /registry/samples/<devfile>
// sampleDevfilePath := path.Join(samplesPath, devfileIndex.Name, devfileName)
// if _, err = os.Stat(sampleDevfilePath); err == nil {
// bytes, err = ioutil.ReadFile(sampleDevfilePath)
// }
// }
// if err != nil {
// log.Print(err.Error())
// c.JSON(http.StatusInternalServerError, gin.H{
// "error": err.Error(),
// "status": fmt.Sprintf("failed to pull the devfile of %s", devfileName),
// })
// return nil
// }

// return bytes
// }
// }

// c.JSON(http.StatusNotFound, gin.H{
// "status": fmt.Sprintf("the devfile of %s didn't exist", devfileName),
// })

// return nil
// }(c, devfileName)

/****/
}

func serveUI(c *gin.Context) {
Expand Down

0 comments on commit 7b8e5ac

Please sign in to comment.