Publish list API. #116

This commit is contained in:
Andrey Smirnov
2015-02-20 11:12:16 +03:00
parent 6e8fd6e907
commit 88ff4493b0
+31 -1
View File
@@ -44,7 +44,37 @@ func parseEscapedPath(path string) string {
// GET /publish
func apiPublishList(c *gin.Context) {
c.JSON(400, gin.H{})
localCollection := context.CollectionFactory().LocalRepoCollection()
localCollection.RLock()
defer localCollection.RUnlock()
snapshotCollection := context.CollectionFactory().SnapshotCollection()
snapshotCollection.RLock()
defer snapshotCollection.RUnlock()
collection := context.CollectionFactory().PublishedRepoCollection()
collection.RLock()
defer collection.RUnlock()
result := make([]*deb.PublishedRepo, 0, collection.Len())
err := collection.ForEach(func(repo *deb.PublishedRepo) error {
err := collection.LoadComplete(repo, context.CollectionFactory())
if err != nil {
return err
}
result = append(result, repo)
return nil
})
if err != nil {
c.Fail(500, err)
return
}
c.JSON(200, result)
}
// POST /publish/:prefix/repos | /publish/:prefix/snapshots