mirror of
https://github.com/nicotsx/ironmount.git
synced 2025-12-10 12:10:51 +01:00
refactor: use different path inside container
This commit is contained in:
33
internal/core/config.go
Normal file
33
internal/core/config.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"github.com/go-playground/validator/v10"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
VolumeRootHost string `mapstructure:"volume_root" validate:"required"`
|
||||
}
|
||||
|
||||
func LoadConfig() Config {
|
||||
var config Config
|
||||
viper.AutomaticEnv()
|
||||
|
||||
viper.BindEnv("volume_root", "VOLUME_ROOT")
|
||||
|
||||
if err := viper.Unmarshal(&config); err != nil {
|
||||
log.Error().Err(err).Msg("Failed to load configuration")
|
||||
panic("Failed to load configuration: " + err.Error())
|
||||
}
|
||||
|
||||
validator := validator.New()
|
||||
if err := validator.Struct(config); err != nil {
|
||||
log.Error().Err(err).Msg("Configuration validation failed")
|
||||
panic("Configuration validation failed: " + err.Error())
|
||||
}
|
||||
|
||||
log.Info().Msgf("Loaded configuration: %+v", config)
|
||||
|
||||
return config
|
||||
}
|
||||
Reference in New Issue
Block a user