Browse Source

增加对sqlite数据库的支持 默认模式为mysql数据库

QM303176530 4 years ago
parent
commit
66393b35f7
3 changed files with 11 additions and 9 deletions
  1. 1 1
      server/config.yaml
  2. 7 7
      server/config/config.go
  3. 3 1
      server/main.go

+ 1 - 1
server/config.yaml

@@ -39,7 +39,7 @@ system:
     use-multipoint: false
     env: 'public'  # Change to "develop" to skip authentication for development mode
     addr: 8888
-    db-type: sqlite
+    db-type: "mysql"
 
 # captcha configuration
 captcha:

+ 7 - 7
server/config/config.go

@@ -2,7 +2,7 @@ package config
 
 type Server struct {
 	Mysql   Mysql   `mapstructure:"mysql" json:"mysql"`
-	Sqlite   Sqlite   `mapstructure:"sqlite" json:"sqlite"`
+	Sqlite  Sqlite  `mapstructure:"sqlite" json:"sqlite"`
 	Qiniu   Qiniu   `mapstructure:"qiniu" json:"qiniu"`
 	Casbin  Casbin  `mapstructure:"casbin" json:"casbin"`
 	Redis   Redis   `mapstructure:"redis" json:"redis"`
@@ -16,7 +16,7 @@ type System struct {
 	UseMultipoint bool   `mapstructure:"use-multipoint" json:"useMultipoint"`
 	Env           string `mapstructure:"env" json:"env"`
 	Addr          int    `mapstructure:"addr" json:"addr"`
-	DbType            string    `mapstructure:"db-type" json:"dbType"`
+	DbType        string `mapstructure:"db-type" json:"dbType"`
 }
 
 type JWT struct {
@@ -62,9 +62,9 @@ type Log struct {
 }
 
 type Sqlite struct {
-	Username     string `mapstructure:"username" json:"username"`
-	Password     string `mapstructure:"password" json:"password"`
-	Path         string `mapstructure:"path" json:"path"`
-	Config       string `mapstructure:"config" json:"config"`
-	LogMode      bool   `mapstructure:"log-mode" json:"logMode"`
+	Username string `mapstructure:"username" json:"username"`
+	Password string `mapstructure:"password" json:"password"`
+	Path     string `mapstructure:"path" json:"path"`
+	Config   string `mapstructure:"config" json:"config"`
+	LogMode  bool   `mapstructure:"log-mode" json:"logMode"`
 }

+ 3 - 1
server/main.go

@@ -8,11 +8,13 @@ import (
 )
 
 func main() {
-	switch global.GVA_CONFIG.System.DbType  {
+	switch global.GVA_CONFIG.System.DbType {
 	case "mysql":
 		initialize.Mysql()
 	case "sqlite":
 		initialize.Sqlite()
+	default:
+		initialize.Mysql()
 	}
 	initialize.DBTables()
 	// 程序结束前关闭数据库链接