videoplayer/proto/conf.go

101 lines
2.6 KiB
Go
Raw Normal View History

package proto
2024-09-22 13:59:33 +08:00
import (
"encoding/json"
"fmt"
"gorm.io/gorm"
"os"
)
var Config ConfigStruct
var SigningKey = []byte{}
var Url_map = map[string]bool{"/login": true, "/register": true, "/uuid": true, "/gqr": true, "/cid/callback": true, "/tool/monitor": true}
const (
MYSQL_USER = "video_t2"
MYSQL_DB = "video_t2"
MYSQL_PASSWORD = "2t2SKHmWEYj2xFKF"
MYSQL_PORT = "3306"
MYSQL_HOST = "127.0.0.1"
2024-06-25 10:28:22 +08:00
MYSQL_DSN = MYSQL_USER + ":" + MYSQL_PASSWORD + "@tcp(" + MYSQL_HOST + ":" + MYSQL_PORT + ")/" + MYSQL_DB + "?charset=utf8mb4&parseTime=True&loc=Local"
REDIS_ADDR = "127.0.0.1:6379"
2024-08-04 21:08:29 +08:00
REDIS_PASSWORD = "lj502138"
REIDS_DB = 2
TOKEN_SECRET = "mfjurnc_32ndj9dfhj"
// 以下是持续集成、部署的配置
CID_BASE_DIR = "/home/lijun/cid/"
2024-08-30 11:28:27 +08:00
// 以下是文件上传的配置
FILE_BASE_DIR = "/home/lijun/file/"
)
2024-08-02 15:02:56 +08:00
const (
// 以下是消息类型
MSG_TYPE_SIMPLE = 1 // 单聊
MSG_TYPE_GROUP = 2 // 群聊
MSG_TYPE_SYSTEM = 3 // 系统消息
MSG_TYPE_FRIEND = 4 // 好友请求
MSG_TYPE_GROUP_ADD = 5 // 加入群聊请求
MSG_TYPE_GROUP_INVI = 6 // 邀请加入群聊
2024-08-02 15:02:56 +08:00
// 以下是消息状态
MSG_STATUS_READ = 1 // 已读
MSG_STATUS_UNREAD = 0 // 未读
)
2024-08-30 11:28:27 +08:00
const (
//文件上传类型
File_TYPE = 1 // 通用文件
//用于视频解析
Video_TYPE = 2 // 视频文件
)
2024-06-28 10:38:55 +08:00
type User struct {
gorm.Model
Name string `gorm:"column:name"`
Age int `gorm:"column:age"`
Email string `gorm:"column:email"`
Gender string `gorm:"column:gender"`
}
2024-09-22 13:59:33 +08:00
type ConfigStruct struct {
DB int `json:"db"` // 0: mysql, 1: pg
MYSQL_DSN string `json:"mysql_dsn"`
PG_DSN string `json:"pg_dsn"`
REDIS_ADDR string `json:"redis_addr"`
TOKEN_USE_REDIS bool `json:"token_use_redis"`
REDIS_User_PW bool `json:"redis_user_pw"` // 是否使用密码
REDIS_PASSWORD string `json:"redis_password"`
REDIS_DB int `json:"redis_db"`
TOKEN_SECRET string `json:"token_secret"`
CID_BASE_DIR string `json:"cid_base_dir"`
FILE_BASE_DIR string `json:"file_base_dir"`
MONITOR bool `json:"monitor"` // 状态监控及邮件通知
SERVER_PORT string `json:"server_port"` // 服务端口
2024-09-22 13:59:33 +08:00
}
// 读取配置文件
func ReadConfig(path string) error {
//读json文件
file, err := os.Open(path)
if err != nil {
fmt.Println("Error opening config file")
return err
}
defer file.Close()
decoder := json.NewDecoder(file)
err = decoder.Decode(&Config)
if err != nil {
fmt.Println("Error decoding config")
2024-11-07 15:55:06 +08:00
} else {
if Config.SERVER_PORT == "" {
Config.SERVER_PORT = "8083" // 默认端口
}
2024-09-22 13:59:33 +08:00
}
SigningKey = []byte(Config.TOKEN_SECRET)
return err
}