1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- 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) Log(c *gin.Context) {
- common.GetLog("common").Info("test log")
- ctrl.RespOk(c, nil)
- }
- 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)
- }
|