You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

59 lines
1.2 KiB

package global
import (
"fmt"
"github.com/go-playground/validator/v10"
"ycmediakit/internal/pkg/config"
"ycmediakit/internal/pkg/logger"
"ycmediakit/internal/pkg/server/ffmpegServer"
"ycmediakit/internal/pkg/server/systemServer"
"go.uber.org/zap"
)
var (
RunConfig *config.RunConfig
AppConfig *config.AppConfig
Logger *zap.Logger
)
var (
PayloadServer *systemServer.PayloadServer
ToHlsServer *ffmpegServer.ToHlsServer
)
func init() {
initConfig()
initLogger()
initServer()
}
func initConfig() {
rCfg := config.NewRunConfig()
aCfg := config.NewAppConfig(rCfg)
validate := validator.New()
err := validate.Struct(rCfg)
if err != nil {
fmt.Println(err)
}
err = validate.Struct(aCfg)
if err != nil {
fmt.Println(err)
}
RunConfig = rCfg
AppConfig = aCfg
}
func initLogger() {
lCfg := &RunConfig.Log
if !lCfg.Separate {
Logger = zap.New(logger.NewCore(lCfg), zap.AddCaller()) //AddCaller()为显示文件名和行号
} else {
Logger = zap.New(logger.NewMultiCore(lCfg), zap.AddCaller()) //AddCaller()为显示文件名和行号
}
zap.ReplaceGlobals(Logger) // 替换 zap 库中全局变量,可以直接通过 zap.L() 访问
}
func initServer() {
PayloadServer = systemServer.NewPayloadServer(&AppConfig.System.Payload)
}