101 lines
2.7 KiB
Go
101 lines
2.7 KiB
Go
package proto
|
|
|
|
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} // 不需要token验证的url
|
|
|
|
const (
|
|
MYSQL_USER = "video_t2"
|
|
MYSQL_DB = "video_t2"
|
|
MYSQL_PASSWORD = "2t2SKHmWEYj2xFKF"
|
|
MYSQL_PORT = "3306"
|
|
MYSQL_HOST = "127.0.0.1"
|
|
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"
|
|
REDIS_PASSWORD = "lj502138"
|
|
REIDS_DB = 2
|
|
|
|
TOKEN_SECRET = "mfjurnc_32ndj9dfhj"
|
|
|
|
// 以下是持续集成、部署的配置
|
|
CID_BASE_DIR = "/home/lijun/cid/"
|
|
|
|
// 以下是文件上传的配置
|
|
FILE_BASE_DIR = "/home/lijun/file/"
|
|
)
|
|
|
|
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 // 邀请加入群聊
|
|
|
|
// 以下是消息状态
|
|
MSG_STATUS_READ = 1 // 已读
|
|
MSG_STATUS_UNREAD = 0 // 未读
|
|
)
|
|
|
|
const (
|
|
//文件上传类型
|
|
File_TYPE = 1 // 通用文件
|
|
//用于视频解析
|
|
Video_TYPE = 2 // 视频文件
|
|
)
|
|
|
|
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"`
|
|
}
|
|
|
|
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"` // 服务端口
|
|
}
|
|
|
|
// 读取配置文件
|
|
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")
|
|
} else {
|
|
if Config.SERVER_PORT == "" {
|
|
Config.SERVER_PORT = "8083" // 默认端口
|
|
}
|
|
}
|
|
SigningKey = []byte(Config.TOKEN_SECRET)
|
|
return err
|
|
}
|