This commit is contained in:
2025-07-03 20:34:31 +08:00
parent 2fce6350c6
commit c67877e811
10 changed files with 163 additions and 69 deletions
+33 -10
View File
@@ -1,15 +1,20 @@
package models
import "github.com/mitchellh/mapstructure"
import (
"fmt"
"os"
"github.com/mitchellh/mapstructure"
)
var Configs map[string]interface{}
var Wed_configs Wed_configs_t
var Configs_wed Configs_web_t
var Configs_user Configs_user_t
var Configs_file Configs_file_t
var Database_configs map[string]interface{}
var User_configs map[string]interface{}
var Allowed_avatar_ext = map[string]bool{
".jpg": true,
".jpeg": true,
@@ -26,17 +31,35 @@ func init() {
}
func All_config_init() {
//读取web配置
err := mapstructure.Decode(Configs["web"].(map[string]interface{}), &Wed_configs)
//初始化数据库
Init_database()
//读取web配置
err := mapstructure.Decode(Configs["web"].(map[string]interface{}), &Configs_wed)
if err != nil {
panic(err)
}
//初始化数据库
Database_init()
//初始化user config
User_configs = Configs["user"].(map[string]interface{})
err = mapstructure.Decode(Configs["user"].(map[string]interface{}), &Configs_user)
if err != nil {
panic(err)
}
//初始化file config
err = mapstructure.Decode(Configs["file"].(map[string]interface{}), &Configs_file)
if err != nil {
panic(err)
}
//创建file的关键文件夹
for _, value := range Configs_file.Pahts {
err := os.MkdirAll(value, 0755)
if err != nil {
fmt.Printf("创建文件夹失败: %v\n", err)
panic("创建文件夹失败")
}
}
}
+18 -1
View File
@@ -1,9 +1,26 @@
package models
type Wed_configs_t struct {
type Configs_web_t struct {
Host string `mapstructure:"host"`
Port string `mapstructure:"port"`
Tls bool `mapstructure:"tls"`
Cert_private_path string `mapstructure:"cert_private_path"`
Cert_public_path string `mapstructure:"cert_public_path"`
}
type Configs_user_t struct {
Cookie_timeout int `mapstructure:"cookie_timeout"`
Pass_hash_type string `mapstructure:"pass_hash_type"`
Avatar_save_path string `mapstructure:"avatar_save_path"`
Avatar_ginrouter_path string `mapstructure:"avatar_ginrouter_path"`
Avatar_path string `mapstructure:"avatar_path"`
}
type Configs_file_t struct {
Max_size_mb uint `mapstructure:"max_size_mb"`
Pahts []string `mapstructure:"pahts"`
Allow_image_mime []map[string]bool `mapstructure:"allow_image_mime"`
Allow_video_mime []map[string]bool `mapstructure:"allow_video_mime"`
Allow_music_mime []map[string]bool `mapstructure:"allow_music_mime"`
Allow_pdf_mime []map[string]bool `mapstructure:"allow_pdf_mime"`
}
+1 -1
View File
@@ -139,7 +139,7 @@ func init() {
}
func Database_init() {
func Init_database() {
fmt.Println("database_init")
//var database_config map[string]interface{}=Configs["database"]
+1 -1
View File
@@ -100,7 +100,7 @@ func Md5_str(str string) string {
}
func Hash_user_pass(str string) string {
switch User_configs["pass_hash_type"].(string) {
switch Configs_user.Pass_hash_type {
case "text":
return str
case "md5":