flores/service/network/create.go
2025-04-18 17:40:44 +08:00

44 lines
821 B
Go

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": "",
})
}