| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- package controller
- import (
- "MeterService/controller/dto"
- "MeterService/core/api"
- "MeterService/core/utils"
- "MeterService/dataStruct"
- "MeterService/database/appApi"
- "github.com/gin-gonic/gin"
- )
- func RegisterApp(c *gin.Context) {
- app := &dto.App{}
- if err := c.BindJSON(app); err != nil {
- api.Fail(c, err.Error())
- return
- }
- db := appApi.NewAppApiDb()
- app.AppSecret = utils.GenerateRandomKey(32, 2)
- err := db.AddOrUpdate(app.ToDbApp())
- if err != nil {
- api.Fail(c, err.Error())
- return
- }
- apiMap := dataStruct.NewMapAppApi()
- apiMap.RemoveAppId(app.AppId)
- for _, v := range app.Apis {
- apiMap.Add(v.Type, &appApi.AppApi{
- AppId: app.AppId,
- Type: v.Type,
- Host: app.Host,
- Url: v.Url,
- })
- }
- resp := &dto.RespApp{
- AppId: app.AppId,
- AppSecret: app.AppSecret,
- }
- api.Ok2(c, resp)
- }
|