|
|
|
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 {
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func Init(filepath string) {
|
|
|
|
var err error
|
|
|
|
c.AddDriver(yaml.Driver)
|
|
|
|
|
|
|
|
err = c.LoadFiles(filepath)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
err = c.BindStruct("", &Config)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("%+v\n", Config)
|
|
|
|
}
|