123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- package controller
- import (
- "encoding/json"
- "github.com/gin-gonic/gin"
- "ppgo/common"
- models "ppgo/entity/model"
- "time"
- )
- type ConfigCtrl struct {
- common.BaseCtl
- }
- type AllRequest struct {
- AppKey string `form:"app_key" binding:"required"`
- Env string `form:"env" binding:"required"`
- }
- func (ctrl ConfigCtrl) All(c *gin.Context) {
- type retStruct struct {
- Name string `json:"name"`
- EndAt string `json:"end_at"`
- Config map[string]interface{} `json:"config"`
- }
- var ret retStruct
- req := &AllRequest{}
- err := c.BindQuery(&req)
- if err != nil {
- ctrl.RespError(c, common.New(common.ParamError))
- return
- }
- app := models.FindByAppKey(req.AppKey)
- if app == nil {
- c.AbortWithStatusJSON(404, map[string]string{"error": "不存在的app"})
- return
- }
- if app.EndAt.Before(time.Now()) {
- ctrl.RespError(c, common.New(common.Expired))
- return
- }
- conf := models.FindConfigByAppKey(app.ID, req.Env)
- json.Unmarshal(conf.Value, &ret.Config)
- ret.Name = app.Name
- ret.EndAt = app.EndAt.Format(time.DateTime)
- ctrl.RespOk(c, ret)
- }
|