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.
 
 

58 lines
1.3 KiB

package config
import (
"github.com/spf13/viper"
"log"
"path/filepath"
"strings"
"ycmediakit/internal/pkg/logger"
"ycmediakit/internal/pkg/server/ffmpegServer"
"ycmediakit/internal/pkg/server/systemServer"
"ycmediakit/internal/pkg/util"
)
type RunConfig struct {
Debug bool ``
Type string ``
Log logger.LogConfig
}
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(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 {
log.Fatalf("read config failed: %v", err)
}
return &cfg
}