Browse Source

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

main
QM303176530 5 years ago
parent
commit
66393b35f7
  1. 2
      server/config.yaml
  2. 14
      server/config/config.go
  3. 4
      server/main.go

2
server/config.yaml

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

14
server/config/config.go

@ -2,7 +2,7 @@ package config
type Server struct { type Server struct {
Mysql Mysql `mapstructure:"mysql" json:"mysql"` Mysql Mysql `mapstructure:"mysql" json:"mysql"`
Sqlite Sqlite `mapstructure:"sqlite" json:"sqlite"`
Sqlite Sqlite `mapstructure:"sqlite" json:"sqlite"`
Qiniu Qiniu `mapstructure:"qiniu" json:"qiniu"` Qiniu Qiniu `mapstructure:"qiniu" json:"qiniu"`
Casbin Casbin `mapstructure:"casbin" json:"casbin"` Casbin Casbin `mapstructure:"casbin" json:"casbin"`
Redis Redis `mapstructure:"redis" json:"redis"` Redis Redis `mapstructure:"redis" json:"redis"`
@ -16,7 +16,7 @@ type System struct {
UseMultipoint bool `mapstructure:"use-multipoint" json:"useMultipoint"` UseMultipoint bool `mapstructure:"use-multipoint" json:"useMultipoint"`
Env string `mapstructure:"env" json:"env"` Env string `mapstructure:"env" json:"env"`
Addr int `mapstructure:"addr" json:"addr"` Addr int `mapstructure:"addr" json:"addr"`
DbType string `mapstructure:"db-type" json:"dbType"`
DbType string `mapstructure:"db-type" json:"dbType"`
} }
type JWT struct { type JWT struct {
@ -62,9 +62,9 @@ type Log struct {
} }
type Sqlite 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"`
} }

4
server/main.go

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

Loading…
Cancel
Save