init commit
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package images
|
||||
|
||||
import (
|
||||
"floares/lib/http/images"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func ListImages(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"data": images.List(),
|
||||
"code": http.StatusOK,
|
||||
})
|
||||
}
|
||||
func PullImage(c *gin.Context) {
|
||||
type Ref struct {
|
||||
Ref string `json:"ref"`
|
||||
}
|
||||
var ref Ref
|
||||
if err := c.ShouldBind(&ref); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": http.StatusBadRequest,
|
||||
"data": gin.H{
|
||||
"err": err.Error(),
|
||||
},
|
||||
})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"data": images.Pull(ref.Ref),
|
||||
"code": http.StatusOK,
|
||||
})
|
||||
}
|
||||
|
||||
func Delete(c *gin.Context) {
|
||||
result := images.Delete(c.Param("id"))
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": http.StatusOK,
|
||||
"err": result.Error,
|
||||
})
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package images
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
func RegisterRouter(c *gin.RouterGroup) {
|
||||
c.GET("/", ListImages)
|
||||
c.POST("/pull", PullImage)
|
||||
c.DELETE("/:id", Delete)
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user