126 lines
3.5 KiB
Go
126 lines
3.5 KiB
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"gopkg.in/ini.v1"
|
|
)
|
|
|
|
var (
|
|
//服务器启动模式
|
|
AppMode string
|
|
//启动端口
|
|
HttpPort string
|
|
//ServerHost
|
|
ServerHost string
|
|
//ServiceName
|
|
ServiceName string
|
|
//WsPort
|
|
WsPort string
|
|
|
|
//redis数据库
|
|
Db string
|
|
//网络地址
|
|
DbHost string
|
|
//数据库端口
|
|
DbPort string
|
|
//数据库用户名
|
|
DbUser string
|
|
//数据库密码
|
|
DbPassWord string
|
|
//数据库名
|
|
DbName string
|
|
//服务id号
|
|
WorkerIDBits int
|
|
|
|
//etcd
|
|
EtcdPort string
|
|
EtcdHost string
|
|
EtcdUser string
|
|
EtcdPassword string
|
|
|
|
//minio
|
|
MinioHost string
|
|
MinioPort string
|
|
MinioUser string
|
|
MinioPassword string
|
|
|
|
//mysql
|
|
MysqlPassWord string
|
|
MysqlHost string
|
|
MysqlPort string
|
|
MysqlUser string
|
|
MysqlDBName string
|
|
|
|
//livekit
|
|
LivekitHost string
|
|
LivekitPort string
|
|
LivekitAppKey string
|
|
LivekitAppSecret string
|
|
)
|
|
|
|
// 初始化函数
|
|
func init() {
|
|
file, err := ini.Load("config.ini")
|
|
if err != nil {
|
|
fmt.Println("配置文件读取失败,请检查文件路径", err)
|
|
}
|
|
LoadServer(file)
|
|
LoadDb(file)
|
|
LoadEtcd(file)
|
|
LoadMinio(file)
|
|
LoadMysql(file)
|
|
LoadLivekit(file)
|
|
}
|
|
|
|
// 读取服务器配置
|
|
func LoadServer(file *ini.File) {
|
|
HttpPort = file.Section("server").Key("HttpPort").MustString("9002")
|
|
WsPort = file.Section("server").Key("WsPort").MustString("8889")
|
|
ServerHost = file.Section("server").Key("ServerHost").MustString("127.0.0.1")
|
|
ServiceName = file.Section("server").Key("ServiceName").MustString("sixqin.test.audioAndVideoCalls")
|
|
WorkerIDBits = file.Section("server").Key("WorkerIDBits").MustInt(3)
|
|
}
|
|
|
|
// 读取redis数据库配置
|
|
func LoadDb(file *ini.File) {
|
|
Db = file.Section("redis").Key("Db").MustString("redis")
|
|
DbHost = file.Section("redis").Key("DbHost").MustString("127.0.0.1")
|
|
DbPort = file.Section("redis").Key("DbPort").MustString("6379")
|
|
DbUser = file.Section("redis").Key("DbUser").MustString("root")
|
|
DbPassWord = file.Section("redis").Key("DbPassWord").MustString("")
|
|
DbName = file.Section("redis").Key("DbName").MustString("iuqt_pushNotificationCenter")
|
|
}
|
|
|
|
// 读取mysql数据库配置
|
|
func LoadMysql(file *ini.File) {
|
|
MysqlHost = file.Section("database").Key("MysqlHost").MustString("127.0.0.1")
|
|
MysqlPort = file.Section("database").Key("MysqlPort").MustString("3306")
|
|
MysqlUser = file.Section("database").Key("MysqlUser").MustString("root")
|
|
MysqlPassWord = file.Section("database").Key("MysqlPassWord").MustString("123456")
|
|
MysqlDBName = file.Section("database").Key("MysqlDBName").MustString("iuqt_acquaintances")
|
|
}
|
|
|
|
// 读取Etcd参数
|
|
func LoadEtcd(file *ini.File) {
|
|
EtcdHost = file.Section("etcd").Key("EtcdHost").MustString("127.0.0.1")
|
|
EtcdPort = file.Section("etcd").Key("EtcdPort").MustString("2379")
|
|
EtcdUser = file.Section("etcd").Key("EtcdUser").MustString("root")
|
|
EtcdPassword = file.Section("etcd").Key("EtcdPassWord").MustString("sixqin@123")
|
|
}
|
|
|
|
// 读取Minio参数
|
|
func LoadMinio(file *ini.File) {
|
|
MinioHost = file.Section("minio").Key("MinioHost").MustString("127.0.0.1")
|
|
MinioPort = file.Section("minio").Key("MinioPort").MustString("7000")
|
|
MinioUser = file.Section("minio").Key("MinioUser").MustString("admin")
|
|
MinioPassword = file.Section("minio").Key("MinioPassword").MustString("1234567890")
|
|
}
|
|
|
|
// 读取livekit参数
|
|
func LoadLivekit(file *ini.File) {
|
|
MinioHost = file.Section("livekit").Key("LivekitHost").MustString("127.0.0.1")
|
|
MinioPort = file.Section("livekit").Key("LivekitPort").MustString("7880")
|
|
MinioUser = file.Section("livekit").Key("LivekitAppKey").MustString("devkey")
|
|
MinioPassword = file.Section("livekit").Key("LivekitAppSecret").MustString("secret")
|
|
}
|