иди, гадюка

package pkg

import (
	"github.com/spf13/viper"

	"goapp/configs"
)

func ViperStruct(path string) (config configs.EnvConfig, err error) {
	viper.AddConfigPath(path)
	viper.SetConfigName(".env")
	viper.SetConfigType("env")
	viper.AutomaticEnv()

	err = viper.ReadInConfig()
	if err != nil {
		return
	}

	err = viper.Unmarshal(&config)
	return
}

func Viper(name string) (res interface{}, err error) {
	viper.SetConfigFile(".env")
	viper.AutomaticEnv()

	err = viper.ReadInConfig()
	if err != nil {
		return nil, err
	}

	res = viper.Get(name)
	return res, nil
}
Restu Wahyu Saputra