InitBaseInfo init base info @Summary init base info @Description init base info @Tags installation @Accept json @Produce json @Param data body install.InitBaseInfoReq true "InitBaseInfoReq" @Success 200 {object} handler.RespBody{} @Router /installation/base-info [post]
(ctx *gin.Context)
| 209 | // @Success 200 {object} handler.RespBody{} |
| 210 | // @Router /installation/base-info [post] |
| 211 | func InitBaseInfo(ctx *gin.Context) { |
| 212 | req := &InitBaseInfoReq{} |
| 213 | if handler.BindAndCheck(ctx, req) { |
| 214 | return |
| 215 | } |
| 216 | req.FormatSiteUrl() |
| 217 | |
| 218 | c, err := conf.ReadConfig(confPath) |
| 219 | if err != nil { |
| 220 | log.Errorf("read config failed %s", err) |
| 221 | handler.HandleResponse(ctx, errors.BadRequest(reason.ReadConfigFailed), nil) |
| 222 | return |
| 223 | } |
| 224 | |
| 225 | if cli.CheckDBTableExist(c.Data.Database) { |
| 226 | log.Warn("database is already initialized") |
| 227 | handler.HandleResponse(ctx, nil, nil) |
| 228 | return |
| 229 | } |
| 230 | |
| 231 | engine, err := data.NewDB(false, c.Data.Database) |
| 232 | if err != nil { |
| 233 | log.Errorf("init database failed %s", err) |
| 234 | handler.HandleResponse(ctx, errors.BadRequest(reason.InstallCreateTableFailed), nil) |
| 235 | } |
| 236 | |
| 237 | inputData := &migrations.InitNeedUserInputData{} |
| 238 | _ = copier.Copy(inputData, req) |
| 239 | if err := migrations.NewMentor(ctx, engine, inputData).InitDB(); err != nil { |
| 240 | log.Error("init database error: ", err.Error()) |
| 241 | handler.HandleResponse(ctx, errors.BadRequest(reason.InstallConfigFailed), schema.ErrTypeAlert) |
| 242 | return |
| 243 | } |
| 244 | |
| 245 | handler.HandleResponse(ctx, nil, nil) |
| 246 | go func() { |
| 247 | time.Sleep(1 * time.Second) |
| 248 | os.Exit(0) |
| 249 | }() |
| 250 | } |
nothing calls this directly
no test coverage detected