72 lines
1.6 KiB
Go
72 lines
1.6 KiB
Go
package intimate
|
|
|
|
import (
|
|
"errors"
|
|
"io/ioutil"
|
|
"log"
|
|
"os"
|
|
|
|
"gopkg.in/yaml.v2"
|
|
)
|
|
|
|
// InitConfig 初始化配置加载 config.yaml(yml)
|
|
var InitConfig *Config
|
|
|
|
func init() {
|
|
InitConfig = &Config{}
|
|
InitConfig.Load()
|
|
// storeOpenrec = NewStore()
|
|
|
|
log.SetFlags(log.Llongfile | log.Ltime)
|
|
|
|
// StoreExtractorDB 全局的Extractor DB 库链接
|
|
StoreExtractorDB = NewStore(InitConfig.Database.ExtractorURI)
|
|
|
|
// TStreamer 全局的Streamer
|
|
TStreamer = StoreExtractorDB.Table("streamer")
|
|
|
|
// TClog 全局的Clog
|
|
TClog = StoreExtractorDB.Table("collect_log")
|
|
|
|
// TStreamerList 全局的streamer list 这个表存的url. 进去可以找到主播的列表. 便于动态更新
|
|
TStreamerList = StoreExtractorDB.Table("streamer_list")
|
|
}
|
|
|
|
// Config 配置
|
|
type Config struct {
|
|
Database struct {
|
|
SourceURI string `yaml:"source_uri"` // "user:password@/dbname"
|
|
ExtractorURI string `yaml:"extractor_uri"`
|
|
} `yaml:"database"`
|
|
}
|
|
|
|
// Load 加载yaml/yml配置
|
|
func (conifg *Config) Load() {
|
|
var configfile string
|
|
configlist := []string{"./config.yaml", "./config.yml", "../../config.yml", "../../config.yaml", "../../../config.yml", "../../../config.yaml"}
|
|
for _, configfile = range configlist {
|
|
if _, err := os.Stat(configfile); err == nil {
|
|
log.Println("find config: ", configfile)
|
|
break
|
|
}
|
|
}
|
|
|
|
if len(configfile) <= 4 {
|
|
log.Panic(errors.New("can't find config.yaml/config.yml"))
|
|
}
|
|
|
|
f, err := os.Open(configfile)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
data, err := ioutil.ReadAll(f)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
err = yaml.Unmarshal(data, conifg)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|