Sun 956e645144 更新v1.3.0-beta24-01-25
Squashed commit of the following:

commit 66d0e5e94c0394d83b47b58bd130ba2addce2930
Author: Sun <95302870@qq.com>
Date:   Thu Jan 25 13:20:34 2024 +0800

    更新1.3.0-beta24-01-25

commit 52a81e5f558b3e7b329f828adbd8255960dd750b
Author: Sun <95302870@qq.com>
Date:   Thu Jan 25 13:13:08 2024 +0800

    Squashed commit of the following:

    commit 908d87357c4e22868eff85f377bb8cd22f3785d7
    Author: Sun <95302870@qq.com>
    Date:   Thu Jan 25 13:12:14 2024 +0800

        增加前端版本号

    commit 8ed2b636476c7a14ae4e1761f7712949b7ce60fc
    Author: Sun <95302870@qq.com>
    Date:   Thu Jan 25 12:29:49 2024 +0800

        增加自动获取前端版本号的git tag

commit ba7d70f9cabf020ab9ce682be5e593b649aed071
Author: Sun <95302870@qq.com>
Date:   Thu Jan 25 10:58:15 2024 +0800

    优化代码

commit 104543b96fb4d5f9362d29da22390d9a0565c395
Author: Sun <95302870@qq.com>
Date:   Wed Jan 24 21:28:31 2024 +0800

    增加系统状态组件的部分样式

commit 70c87c94c688a14d3bbe53be191c2186ec469a01
Author: Sun <95302870@qq.com>
Date:   Wed Jan 24 20:55:05 2024 +0800

    时间组件和搜索栏组件增加样式类型

commit 6bab5a264fdb1281763d73bf022335667845dc67
Author: Sun <95302870@qq.com>
Date:   Wed Jan 24 20:41:33 2024 +0800

    将项目列表增加样式并优化减少dom嵌套

commit 99d18df7f0a57ec1cead9bce7b2b4b11427cc2e2
Author: Sun <95302870@qq.com>
Date:   Wed Jan 24 20:11:07 2024 +0800

    增加系统状态、logo等类名并简化部分组件dom

commit bf1cc0cc0014f751b6453ebfb357b575b0a54615
Author: Sun <95302870@qq.com>
Date:   Wed Jan 24 17:17:41 2024 +0800

    更新关于页面

commit fceacf58b87b988827f0baa6086e8296c843c495
Author: Sun <95302870@qq.com>
Date:   Wed Jan 24 14:54:37 2024 +0800

    增加隐藏网络模式切换开关

commit e0dcc49f5b23618103c5ee15e13758164d2eddf2
Author: Sun <95302870@qq.com>
Date:   Wed Jan 24 13:55:28 2024 +0800

    优化部分错误码

commit 863cdf0fc1fc406304784d4304ba6be31e5133ff
Author: Sun <95302870@qq.com>
Date:   Wed Jan 24 12:54:55 2024 +0800

    声明暴露端口

commit 5b25ef9c194dc0112cd10250c04344dd6f57be27
Author: Sun <95302870@qq.com>
Date:   Wed Jan 24 12:38:48 2024 +0800

    修改命令行所有的输出内容为英文
2024-01-25 13:21:47 +08:00

197 lines
5.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package initialize
import (
"flag"
"fmt"
"os"
"sun-panel/global"
"sun-panel/initialize/cUserToken"
"sun-panel/initialize/config"
"sun-panel/initialize/database"
"sun-panel/initialize/lang"
"sun-panel/initialize/other"
"sun-panel/initialize/redis"
"sun-panel/initialize/runlog"
"sun-panel/initialize/systemSettingCache"
"sun-panel/initialize/userToken"
"sun-panel/lib/cmn"
"sun-panel/models"
"sun-panel/structs"
"time"
"log"
"github.com/gin-gonic/gin"
)
var DB_DRIVER = database.SQLITE
// var RUNCODE = "debug"
// var ISDOCER = "" // 是否为docker模式
func InitApp() error {
Logo()
gin.SetMode(global.RUNCODE) // GIN 运行模式
// 日志
if logger, err := runlog.InitRunlog(global.RUNCODE, "running.log"); err != nil {
log.Panicln("Log initialization error", err)
panic(err)
} else {
global.Logger = logger
}
// 命令行运行
CommandRun()
// 配置初始化
{
if config, err := config.ConfigInit(); err != nil {
global.Logger.Errorln("Configuration initialization error", err)
return err
} else {
global.Config = config
}
}
// 多语言初始化
lang.LangInit("zh-cn") // en-us
DatabaseConnect()
// Redis 连接
{
// 判断是否有使用redis的驱动没有将不连接
cacheDrive := global.Config.GetValueString("base", "cache_drive")
queueDrive := global.Config.GetValueString("base", "queue_drive")
if cacheDrive == "redis" || queueDrive == "redis" {
redisConfig := structs.IniConfigRedis{}
global.Config.GetSection("redis", &redisConfig)
rdb, err := redis.InitRedis(redis.Options{
Addr: redisConfig.Address,
Password: redisConfig.Password,
DB: redisConfig.Db,
})
if err != nil {
log.Panicln("Redis initialization error", err)
panic(err)
// return err
}
global.RedisDb = rdb
}
}
// 初始化用户token
global.UserToken = userToken.InitUserToken()
global.CUserToken = cUserToken.InitCUserToken()
// 其他的初始化
global.VerifyCodeCachePool = other.InitVerifyCodeCachePool()
global.SystemSetting = systemSettingCache.InItSystemSettingCache()
global.SystemMonitor = global.NewCache[interface{}](5*time.Hour, -1, "systemMonitorCache")
return nil
}
func DatabaseConnect() {
// 数据库连接 - 开始
var dbClientInfo database.DbClient
databaseDrive := global.Config.GetValueStringOrDefault("base", "database_drive")
if databaseDrive == database.MYSQL {
dbClientInfo = &database.MySQLConfig{
Username: global.Config.GetValueStringOrDefault("mysql", "username"),
Password: global.Config.GetValueStringOrDefault("mysql", "password"),
Host: global.Config.GetValueStringOrDefault("mysql", "host"),
Port: global.Config.GetValueStringOrDefault("mysql", "port"),
Database: global.Config.GetValueStringOrDefault("mysql", "db_name"),
WaitTimeout: global.Config.GetValueInt("mysql", "wait_timeout"),
}
} else {
dbClientInfo = &database.SQLiteConfig{
Filename: global.Config.GetValueStringOrDefault("sqlite", "file_path"),
}
}
if db, err := database.DbInit(dbClientInfo); err != nil {
log.Panicln("Database initialization error", err)
panic(err)
} else {
global.Db = db
models.Db = global.Db
}
database.CreateDatabase(databaseDrive, global.Db)
database.NotFoundAndCreateUser(global.Db)
}
// 命令行运行
func CommandRun() {
var (
cfg bool
pwd bool
)
flag.BoolVar(&cfg, "config", false, "Generate configuration file")
flag.BoolVar(&pwd, "password-reset", false, "Reset the password of the first user")
flag.Parse()
if cfg {
// 生成配置文件
fmt.Println("Generating configuration file")
cmn.AssetsTakeFileToPath("conf.example.ini", "conf/conf.example.ini")
cmn.AssetsTakeFileToPath("conf.example.ini", "conf/conf.ini")
fmt.Println("The configuration file has been created conf/conf.ini ", "Please modify according to your own needs")
os.Exit(0) // 务必退出
} else if pwd {
// 重置密码
// 配置初始化
config, _ := config.ConfigInit()
global.Config = config
DatabaseConnect()
userInfo := models.User{}
if err := global.Db.Where("role=?", 1).Order("id").First(&userInfo).Error; err != nil {
fmt.Println("ERROR", err.Error())
os.Exit(0) // 务必退出
}
newPassword := "12345678"
updateInfo := models.User{
Password: cmn.PasswordEncryption(newPassword),
Token: "",
}
// 重置第一个管理员的密码
if err := global.Db.Select("Password", "Token").Where("id=?", userInfo.ID).Updates(&updateInfo).Error; err != nil {
fmt.Println("ERROR", err.Error())
os.Exit(0) // 务必退出
}
fmt.Println("The password has been successfully reset. Here is the account information")
fmt.Println("Username ", userInfo.Username)
fmt.Println("Password ", newPassword)
os.Exit(0) // 务必退出
} else {
return
}
os.Exit(0) // 务必退出
}
func Logo() {
fmt.Println(" ____ ___ __")
fmt.Println(" / __/_ _____ / _ \\___ ____ ___ / /")
fmt.Println(" _\\ \\/ // / _ \\ / ___/ _ `/ _ \\/ -_) / ")
fmt.Println(" /___/\\_,_/_//_/ /_/ \\_,_/_//_/\\__/_/ ")
fmt.Println("")
versionInfo := cmn.GetSysVersionInfo()
fmt.Println("Version:", versionInfo.Version)
fmt.Println("Welcome to the Sun-Panel.")
fmt.Println("Project address:", "https://github.com/hslr-s/sun-panel")
}