|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"git.noahlan.cn/northlan/ntools-go/logger"
|
|
|
|
c "github.com/gookit/config/v2"
|
|
|
|
"github.com/gookit/config/v2/yaml"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
var Config config
|
|
|
|
|
|
|
|
type (
|
|
|
|
Kafka struct {
|
|
|
|
Addr []string
|
|
|
|
Topic string
|
|
|
|
}
|
|
|
|
config struct {
|
|
|
|
Bilibili struct {
|
|
|
|
Enabled bool // 是否启用
|
|
|
|
Url string // 弹幕服务器url
|
|
|
|
GetRoomUrl string // 获取房间信息url
|
|
|
|
RoomId int64 // 待连接roomId
|
|
|
|
UserId int64 // 用于连接的userId,0则随机生成
|
|
|
|
HeartbeatInterval time.Duration // 心跳间隔 单位s
|
|
|
|
}
|
|
|
|
// Log 日志配置
|
|
|
|
Log struct {
|
|
|
|
File logger.FileConfig
|
|
|
|
Console logger.ConsoleConfig
|
|
|
|
}
|
|
|
|
// Kafka 队列配置
|
|
|
|
Kafka struct {
|
|
|
|
Danmaku Kafka
|
|
|
|
Gift Kafka
|
|
|
|
GuardBuy Kafka
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func Init(filepath string) {
|
|
|
|
var err error
|
|
|
|
c.AddDriver(yaml.Driver)
|
|
|
|
|
|
|
|
err = c.LoadFiles(filepath)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("读取配置文件错误", err)
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
err = c.BindStruct("", &Config)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("解析配置文件错误", err)
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("%+v\n", Config)
|
|
|
|
}
|