You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
1.5 KiB
Go
74 lines
1.5 KiB
Go
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 BilibiliType string
|
|
|
|
const (
|
|
BilibiliTypeOfficial BilibiliType = "official"
|
|
BilibiliTypeCustom BilibiliType = "custom"
|
|
)
|
|
|
|
type (
|
|
Kafka struct {
|
|
Addr []string
|
|
Topic string
|
|
}
|
|
config struct {
|
|
Bilibili struct {
|
|
Enabled bool // 是否启用
|
|
Type BilibiliType // 类型
|
|
Official struct {
|
|
Api string // API 地址
|
|
AkId string // accessKeyId
|
|
AkSecret string // accessSecret
|
|
} // 官方API
|
|
Custom struct {
|
|
Url string // 弹幕服务器url
|
|
}
|
|
ResetInterval time.Duration // 重连间隔
|
|
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)
|
|
}
|