提交 8c62ee93 编写于 作者: R rikugun

feat: 增加sqlite 支持

上级 80120834
......@@ -25,3 +25,5 @@ yarn-error.log*
go.sum
/server/log/
/server/latest_log
*.iml
......@@ -2,6 +2,7 @@ package config
type Server struct {
Mysql Mysql `mapstructure:"mysql" json:"mysql"`
Sqlite Sqlite `mapstructure:"sqlite" json:"sqlite"`
Qiniu Qiniu `mapstructure:"qiniu" json:"qiniu"`
Casbin Casbin `mapstructure:"casbin" json:"casbin"`
Redis Redis `mapstructure:"redis" json:"redis"`
......@@ -15,6 +16,7 @@ type System struct {
UseMultipoint bool `mapstructure:"use-multipoint" json:"useMultipoint"`
Env string `mapstructure:"env" json:"env"`
Addr int `mapstructure:"addr" json:"addr"`
Db string `mapstructure:"db" json:"db"`
}
type JWT struct {
......@@ -58,3 +60,11 @@ type Log struct {
Stdout string `mapstructure:"stdout" json:"stdout"`
File string `mapstructure:"file" json:"file"`
}
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"`
}
package initialize
import (
"fmt"
"gin-vue-admin/global"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/sqlite"
)
//初始化数据库并产生数据库全局变量
func Sqlite() {
admin := global.GVA_CONFIG.Sqlite
if db, err := gorm.Open("sqlite3", fmt.Sprintf("%s?%s", admin.Path,admin.Config)); err != nil {
global.GVA_LOG.Error("DEFAULTDB数据库启动异常", err)
} else {
global.GVA_DB = db
global.GVA_DB.LogMode(admin.LogMode)
}
}
......@@ -8,7 +8,12 @@ import (
)
func main() {
initialize.Mysql()
switch global.GVA_CONFIG.System.Db {
case "mysql":
initialize.Mysql()
case "sqlite":
initialize.Sqlite()
}
initialize.DBTables()
// 程序结束前关闭数据库链接
defer global.GVA_DB.Close()
......
package utils
import "os"
import (
"os"
"path/filepath"
)
// @title PathExists
// @description 文件目录是否存在
......@@ -45,3 +48,13 @@ func CreateDir(dirs ...string) (err error) {
}
return err
}
// @title cwd
// @description 获取当前工作目录
// @return string
func CWD() string {
path, err := os.Executable()
if err != nil {
return ""
}
return filepath.Dir(path)
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册