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