feat:完善项目信息

This commit is contained in:
henry
2021-12-28 17:14:02 +08:00
parent ae25321694
commit 40168a30b3
12 changed files with 339 additions and 70 deletions

View File

@ -1,6 +1,9 @@
package migrate
import (
"SciencesServer/app/common/migrate"
"SciencesServer/serve/orm"
"SciencesServer/serve/orm/logic"
"fmt"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
@ -63,19 +66,19 @@ func run() {
fmt.Println("========================\n=== 初始化项目配置 ===\n========================")
// 初始化数据引擎
//engine := orm.NewInstance(
// orm.WithDBMode(mode),
// orm.WithMysqlOption(&logic.Mysql{
// Host: _mysql.Host, Port: _mysql.Port,
// Username: _mysql.Username, Password: _mysql.Password,
// Database: _mysql.Database, Parameters: "charset=utf8mb4,utf8&parseTime=True&loc=Local",
// }),
// orm.WithSqliteOption(&logic.Sqlite{Path: _sqlite.Path, Name: _sqlite.Name}),
//).Init()
engine := orm.NewInstance(
orm.WithDBMode(mode),
orm.WithMysqlOption(&logic.Mysql{
Host: _mysql.Host, Port: _mysql.Port,
Username: _mysql.Username, Password: _mysql.Password,
Database: _mysql.Database, Parameters: "charset=utf8mb4,utf8&parseTime=True&loc=Local",
}),
orm.WithSqliteOption(&logic.Sqlite{Path: _sqlite.Path, Name: _sqlite.Name}),
).Init()
fmt.Println("========================\n=== 数据引擎创建成功 ===\n========================")
// 迁移数据
//migrate.NewInstance(migrate.WithGormDBOption(engine.Engine)).Handle()
migrate.NewInstance(migrate.WithGormDBOption(engine.Engine)).Handle()
if err := saveFile(file, &Config{
Debug: true,

View File

@ -14,7 +14,6 @@ import (
"SciencesServer/tools"
"SciencesServer/utils"
"fmt"
"github.com/gin-gonic/gin"
"github.com/spf13/cobra"
"strings"
)
@ -39,15 +38,14 @@ func init() {
func run() {
fmt.Println("========================\n==== 启动项目服务 ====\n========================")
// 载入配置信息
utils.LoadConfig(configFile, config.SettingInfo, func(i interface{}) {
obj := i.(*config.Setting)
obj.Upload.Exts = strings.Split(obj.Upload.Ext, ",")
logger.NewLogger().Init(&logger.Option{File: obj.Log.File, LeastDay: obj.Log.LeastDay, Level: obj.Log.Level, IsStdout: false}).Load()
})
fmt.Println(engineFile)
// 载入数据引擎配置
utils.LoadConfig(engineFile, config.EngineInfo, func(i interface{}) {
fmt.Println(utils.AnyToJSON(i))
obj := i.(*config.Engine)
orm.NewInstance(
@ -75,7 +73,7 @@ func run() {
Port: config.SettingInfo.Server.Port, ReadTimeout: config.SettingInfo.Server.ReadTimeout,
WriteTimeout: config.SettingInfo.Server.WriteTimeout, IdleTimeout: config.SettingInfo.Server.IdleTimeout,
}).Run(router.NewRouter(&router.Option{
Mode: gin.DebugMode, IsCors: true,
Mode: config.Mode, IsCors: true,
RateLimitConfig: &router.RateLimitConfig{
IsRate: true, Limit: config.SettingInfo.Rate.Limit, Capacity: config.SettingInfo.Rate.Capacity,
},