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.3 KiB

package config
import (
"log"
"path/filepath"
"strings"
"ycmediakit/internal/pkg/server/ffmpegServer"
"ycmediakit/internal/pkg/server/systemServer"
"ycmediakit/internal/pkg/unit/logger"
"ycmediakit/internal/pkg/util"
"github.com/spf13/viper"
)
type RunConfig struct {
Debug bool ``
Type string ``
Log logger.Config
}
type AppConfig struct {
Server ServerConfig ``
System systemServer.SystemConfig ``
Ffmpeg ffmpegServer.FfmpegConfig ``
}
type ServerConfig struct {
Port string
}
func NewRunConfig() *RunConfig {
v := viper.New()
v.AddConfigPath(filepath.Join(util.GetWorkPath(), "config"))
v.SetConfigName("config")
v.SetConfigType("yaml")
if err := v.ReadInConfig(); err != nil {
log.Fatalf("read config failed: %v", err)
}
var cfg RunConfig
if err := v.Unmarshal(&cfg); err != nil {
log.Fatalf("read config failed: %v", err)
}
return &cfg
}
func NewAppConfig(cfg *RunConfig) *AppConfig {
v := viper.New()
v.AddConfigPath(filepath.Join(util.GetWorkPath(), "config"))
v.SetConfigName(strings.Join([]string{"config", ".", cfg.Type}, ""))
v.SetConfigType("yaml")
if err := v.ReadInConfig(); err != nil {
log.Fatalf("read config failed: %v", err)
}
var appCfg AppConfig
if err := v.Unmarshal(&appCfg); err != nil {
log.Fatalf("read config failed: %v", err)
}
return &appCfg
}