MCPcopy Index your code
hub / github.com/TruthHun/DocHub / Install

Method Install

controllers/HomeControllers/InstallController.go:26–73  ·  view source on GitHub ↗

安装程序

()

Source from the content-addressed store, hash-verified

24
25//安装程序
26func (this *InstallController) Install() {
27 if helper.IsInstalled { //如果程序已安装,在访问该路由是,跳转到首页
28 this.Redirect("/", 302)
29 return
30 }
31 if this.Ctx.Request.Method == "GET" {
32 this.TplName = "Install/install.html"
33 return
34 }
35
36 var form installForm
37 var respData = map[string]interface{}{"status": 0}
38
39 this.ParseForm(&form)
40
41 if form.Charset == "" {
42 respData["msg"] = "请选择您创建的数据库字符编码!!!请选择您创建的数据库字符编码!!!请选择您创建的数据库字符编码!!!"
43 } else if form.Database == "" || form.Host == "" || form.Username == "" || form.Port <= 0 {
44 respData["msg"] = "所有必填输入项均不能为空,请按要求进行填写"
45 } else {
46 if err := models.CheckDatabaseIsExist(form.Host, form.Port, form.Username, form.Password, form.Database); err != nil {
47 respData["msg"] = "数据库连接失败:" + err.Error()
48 } else {
49 //生成app.conf配置项
50 if form.Prefix = strings.TrimSpace(form.Prefix); form.Prefix == "" {
51 form.Prefix = "hc_"
52 }
53 if err = helper.GenerateAppConf(form.Host, form.Port, form.Username, form.Password, form.Database, form.Prefix, form.Charset); err == nil {
54 //重载app.conf
55 if err = beego.LoadAppConfig("ini", "conf/app.conf"); err == nil {
56 //初始化数据库
57 models.Init()
58 //将安装设置为true
59 helper.IsInstalled = true
60 respData["msg"] = "程序安装成功"
61 respData["status"] = 1
62 } else {
63 respData["msg"] = "重载配置文件失败:" + err.Error()
64 }
65 } else {
66 respData["msg"] = "生成配置文件失败:" + err.Error()
67 }
68 }
69 }
70
71 this.Data["json"] = respData
72 this.ServeJSON()
73}

Callers

nothing calls this directly

Calls 2

ParseFormMethod · 0.80
InitMethod · 0.80

Tested by

no test coverage detected