initial commit
This commit is contained in:
20
config/config.go
Normal file
20
config/config.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
func ReadConfig() error {
|
||||
configPath := viper.GetString("config")
|
||||
if configPath == "" {
|
||||
return fmt.Errorf("config file path is empty")
|
||||
}
|
||||
viper.SetConfigFile(configPath)
|
||||
viper.SetConfigType("yaml")
|
||||
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
return fmt.Errorf("reading config file %s: %w", configPath, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
8
config/env.go
Normal file
8
config/env.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package config
|
||||
|
||||
import "github.com/spf13/viper"
|
||||
|
||||
func CollectEnv() {
|
||||
viper.SetEnvPrefix("NETBOUNCE_")
|
||||
_ = viper.BindEnv("config", "CONFIG")
|
||||
}
|
||||
Reference in New Issue
Block a user