package config import ( "github.com/spf13/viper" "log" "path/filepath" "strings" "ycmediakit/internal/pkg/logger" "ycmediakit/internal/pkg/server/ffmpegServer" "ycmediakit/internal/pkg/util" ) type RunConfig struct { Debug bool `` Type string `` Log logger.LogConfig } type AppConfig struct { Server ServerConfig `` Ffmpeg ffmpegServer.FfmpegConfig `` } type ServerConfig struct { Port string } func init() { } 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 { } return &cfg } func NewAppConfig(runConfig *RunConfig) *AppConfig { v := viper.New() v.AddConfigPath(filepath.Join(util.GetWorkPath(), "config")) v.SetConfigName(strings.Join([]string{"config", ".", runConfig.Type}, "")) v.SetConfigType("yaml") if err := v.ReadInConfig(); err != nil { log.Fatalf("read config failed: %v", err) } var cfg AppConfig if err := v.Unmarshal(&cfg); err != nil { } return &cfg }