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.

60 lines
1.1 KiB
Go

3 years ago
package config
import (
"fmt"
c "github.com/gookit/config/v2"
"github.com/gookit/config/v2/yaml"
"live-gateway/pkg/logger"
"path/filepath"
"runtime"
"time"
)
3 years ago
var (
_, b, _, _ = runtime.Caller(0)
Root = filepath.Join(filepath.Dir(b), "../")
)
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
}
}
)
func init() {
var err error
c.AddDriver(yaml.Driver)
err = c.LoadFiles(Root + "/config.yml")
if err != nil {
panic(err)
}
err = c.BindStruct("", &Config)
if err != nil {
panic(err)
}
fmt.Printf("%+v\n", Config)
3 years ago
}