InitEnvironment init environment @Summary init environment @Description init environment @Tags installation @Accept json @Produce json @Param data body install.CheckDatabaseReq true "CheckDatabaseReq" @Success 200 {object} handler.RespBody{} @Router /installation/init [post]
(ctx *gin.Context)
| 157 | // @Success 200 {object} handler.RespBody{} |
| 158 | // @Router /installation/init [post] |
| 159 | func InitEnvironment(ctx *gin.Context) { |
| 160 | req := &CheckDatabaseReq{} |
| 161 | if handler.BindAndCheck(ctx, req) { |
| 162 | return |
| 163 | } |
| 164 | |
| 165 | // check config file if exist |
| 166 | if cli.CheckConfigFile(confPath) { |
| 167 | log.Debug("config file already exists") |
| 168 | handler.HandleResponse(ctx, nil, nil) |
| 169 | return |
| 170 | } |
| 171 | |
| 172 | if err := cli.InstallConfigFile(confPath); err != nil { |
| 173 | handler.HandleResponse(ctx, errors.BadRequest(reason.InstallConfigFailed), &InitEnvironmentResp{ |
| 174 | Success: false, |
| 175 | CreateConfigFailed: true, |
| 176 | DefaultConfig: string(configs.Config), |
| 177 | ErrType: schema.ErrTypeAlert.ErrType, |
| 178 | }) |
| 179 | return |
| 180 | } |
| 181 | |
| 182 | c, err := conf.ReadConfig(confPath) |
| 183 | if err != nil { |
| 184 | log.Errorf("read config failed %s", err) |
| 185 | handler.HandleResponse(ctx, errors.BadRequest(reason.ReadConfigFailed), nil) |
| 186 | return |
| 187 | } |
| 188 | c.Data.Database.Driver = req.DbType |
| 189 | c.Data.Database.Connection = req.GetConnection() |
| 190 | c.Data.Cache.FilePath = filepath.Join(path.CacheDir, path.DefaultCacheFileName) |
| 191 | c.I18n.BundleDir = path.I18nPath |
| 192 | c.ServiceConfig.UploadPath = path.UploadFilePath |
| 193 | |
| 194 | if err := conf.RewriteConfig(confPath, c); err != nil { |
| 195 | log.Errorf("rewrite config failed %s", err) |
| 196 | handler.HandleResponse(ctx, errors.BadRequest(reason.ReadConfigFailed), nil) |
| 197 | return |
| 198 | } |
| 199 | handler.HandleResponse(ctx, nil, nil) |
| 200 | } |
| 201 | |
| 202 | // InitBaseInfo init base info |
| 203 | // @Summary init base info |
nothing calls this directly
no test coverage detected