MCPcopy
hub / github.com/apache/devlake / initConfig

Function initConfig

backend/core/config/config_viper.go:41–89  ·  view source on GitHub ↗
(v *viper.Viper)

Source from the content-addressed store, hash-verified

39}
40
41func initConfig(v *viper.Viper) {
42 if envFile := os.Getenv("ENV_FILE"); envFile != "" {
43 v.SetConfigFile(envFile)
44 } else {
45 v.SetConfigName(getConfigName())
46 v.SetConfigType("env")
47 envPath := getEnvPath()
48 v.AddConfigPath(envPath)
49
50 paths := []string{
51 "./../../../../..",
52 "./../../../..",
53 "./../../..",
54 "./../..",
55 "./..",
56 "./",
57 }
58 for _, path := range paths {
59 v.AddConfigPath(path)
60 }
61
62 for _, path := range paths {
63 filePath := filepath.Join(path, getConfigName())
64 fileInfo, err := os.Stat(filePath)
65 if err == nil && !fileInfo.IsDir() {
66 envFile = filePath
67 break
68 }
69 }
70 v.SetConfigFile(envFile)
71 }
72
73 if _, err := os.Stat(v.ConfigFileUsed()); err != nil {
74 if os.IsNotExist(err) {
75 logrus.Info("no [.env] file, devlake will read configuration from environment, please make sure you have set correct environment variable.")
76 } else {
77 panic(fmt.Errorf("failed to get config file info: %v", err))
78 }
79 } else {
80 if err := v.ReadInConfig(); err != nil {
81 panic(fmt.Errorf("failed to read configuration file: %v", err))
82 }
83 // This line is essential for reading
84 v.WatchConfig()
85 }
86
87 v.AutomaticEnv()
88 setDefaultValue(v)
89}
90
91func getConfigName() string {
92 return defaultConfigName

Callers 1

initFunction · 0.85

Calls 4

getConfigNameFunction · 0.85
getEnvPathFunction · 0.85
setDefaultValueFunction · 0.85
InfoMethod · 0.65

Tested by

no test coverage detected