restful api
This commit is contained in:
parent
9e748a50df
commit
a19b70610e
4
main.go
4
main.go
|
|
@ -60,7 +60,7 @@ func main() {
|
|||
r.POST("/dep", controller.CreateDeleteDeployment)
|
||||
r.DELETE("/dep", controller.CreateDeleteDeployment)
|
||||
|
||||
r.GET("/pod", controller.GetPodStatus)
|
||||
r.GET("/pod/:id", controller.GetPodStatus)
|
||||
|
||||
r.GET("/login", LoginToken)
|
||||
r.Any("/test_token", TestToken)
|
||||
|
|
@ -71,6 +71,8 @@ func main() {
|
|||
r.POST("/file/:app/:filename", controller.GetPostOrDeleteFile)
|
||||
r.DELETE("/file/:app/:filename", controller.GetPostOrDeleteFile)
|
||||
|
||||
r.POST("/fork", controller.ForkApp)
|
||||
|
||||
err := r.Run(":8000")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ package controller
|
|||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
log "github.com/sirupsen/logrus"
|
||||
k8s_manager "k8s-manager/src"
|
||||
"k8s-manager/src/model"
|
||||
"k8s-manager/src/service"
|
||||
"k8s.io/api/apps/v1"
|
||||
|
|
@ -23,17 +25,12 @@ type DeployStatusObject struct {
|
|||
|
||||
func CreateDeleteDeployment(c *gin.Context) {
|
||||
tokenUsername := c.MustGet("username").(string)
|
||||
id := c.Query("id")
|
||||
if strings.TrimSpace(id) == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"msg": "no app id"})
|
||||
return
|
||||
}
|
||||
appId, err := strconv.Atoi(id)
|
||||
app := &model.AppModel{}
|
||||
err := c.BindJSON(app)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"msg": "wrong id"})
|
||||
return
|
||||
log.WithError(err).Error("CreateDeleteDeployment BindJSON")
|
||||
k8s_manager.GinError(c, http.StatusBadRequest, err.Error())
|
||||
}
|
||||
app := model.AppModel{Id: appId}
|
||||
if app.Fill() != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"msg": "wrong id"})
|
||||
return
|
||||
|
|
@ -43,9 +40,9 @@ func CreateDeleteDeployment(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
if c.Request.Method == http.MethodPost {
|
||||
K.CreateApp(&app)
|
||||
K.CreateApp(app)
|
||||
} else if c.Request.Method == http.MethodDelete {
|
||||
K.DeleteApp(&app)
|
||||
K.DeleteApp(app)
|
||||
} else {
|
||||
c.JSON(http.StatusMethodNotAllowed, gin.H{"msg": "unsupported method"})
|
||||
}
|
||||
|
|
@ -53,7 +50,7 @@ func CreateDeleteDeployment(c *gin.Context) {
|
|||
}
|
||||
|
||||
func GetPodStatus(c *gin.Context) {
|
||||
id := c.Query("id")
|
||||
id := c.Param("id")
|
||||
if strings.TrimSpace(id) == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"msg": "no app id"})
|
||||
return
|
||||
|
|
|
|||
Loading…
Reference in New Issue