finish work
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
package network
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"floares/lib/http/network"
|
||||
"floares/lib/model"
|
||||
"github.com/gin-gonic/gin"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
@@ -20,10 +23,37 @@ func Disconnect(c *gin.Context) {
|
||||
"err": "",
|
||||
})
|
||||
}
|
||||
|
||||
func Connect(c *gin.Context) {
|
||||
ns := c.Param("ns")
|
||||
id := c.Query("id")
|
||||
err := network.Connect(ns, id)
|
||||
var req model.ConnectRequest
|
||||
json.NewDecoder(c.Request.Body).Decode(&req)
|
||||
err := network.Connect(ns, req)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"err": "",
|
||||
})
|
||||
}
|
||||
func ConnectALl(c *gin.Context) {
|
||||
type Containers struct {
|
||||
Name string `json:"name"`
|
||||
Id []string `json:"id"`
|
||||
}
|
||||
var id Containers
|
||||
err := json.NewDecoder(c.Request.Body).Decode(&id)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
err = network.MakerNet(id.Name, id.Id)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": err.Error(),
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package network
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"floares/lib/http/network"
|
||||
"floares/lib/model"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func Create(c *gin.Context) {
|
||||
var req model.CreateNetworkRequest
|
||||
json.NewDecoder(c.Request.Body).Decode(&req)
|
||||
err := network.Create(req)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": http.StatusBadRequest,
|
||||
"error": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": http.StatusOK,
|
||||
"error": "",
|
||||
})
|
||||
}
|
||||
|
||||
func Delete(c *gin.Context) {
|
||||
var req model.CreateNetworkRequest
|
||||
json.NewDecoder(c.Request.Body).Decode(&req)
|
||||
err := network.Delete(req.Name)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": http.StatusBadRequest,
|
||||
"err": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": http.StatusOK,
|
||||
"err": "",
|
||||
})
|
||||
}
|
||||
@@ -7,5 +7,8 @@ func RegisterRouter(r *gin.RouterGroup) {
|
||||
r.GET("/:ns/inspect", ListConnect)
|
||||
r.DELETE("/:ns/disconnect", Disconnect)
|
||||
r.POST("/:ns/connect", Connect)
|
||||
r.POST("/group", ConnectALl)
|
||||
r.POST("/create", Create)
|
||||
r.POST("/delete", Delete)
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package volume
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"floares/lib/http/volume"
|
||||
"floares/lib/model"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func Create(c *gin.Context) {
|
||||
var req model.CreateVolume
|
||||
if err := json.NewDecoder(c.Request.Body).Decode(&req); err != nil {
|
||||
c.JSON(200, gin.H{
|
||||
"code": 400,
|
||||
"err": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
err := volume.Create(req)
|
||||
if err != nil {
|
||||
c.JSON(200, gin.H{
|
||||
"code": 400,
|
||||
"err": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
c.JSON(200, gin.H{
|
||||
"code": 200,
|
||||
"err": "",
|
||||
})
|
||||
}
|
||||
func Delete(c *gin.Context) {
|
||||
|
||||
err := volume.Delete(c.Param("id"))
|
||||
if err != nil {
|
||||
c.JSON(200, gin.H{
|
||||
"code": 400,
|
||||
"err": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
c.JSON(200, gin.H{
|
||||
"code": 200,
|
||||
"err": "",
|
||||
})
|
||||
}
|
||||
@@ -4,4 +4,7 @@ import "github.com/gin-gonic/gin"
|
||||
|
||||
func RegisterRouter(c *gin.RouterGroup) {
|
||||
c.GET("/", List)
|
||||
c.POST("/", Create)
|
||||
c.DELETE("/:id", Delete)
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user