initConfig reads in config file and ENV variables if set.
()
| 105 | |
| 106 | // initConfig reads in config file and ENV variables if set. |
| 107 | func initConfig() { |
| 108 | viper.AutomaticEnv() // read in environment variables that match |
| 109 | configFile := viper.GetString(varConfig) |
| 110 | |
| 111 | // If a custom config file is specified by flag or env var, use it. Otherwise use default file. |
| 112 | if len(configFile) > 0 { |
| 113 | if len(configFile) < 5 || strings.ToLower(configFile[len(configFile)-5:]) != ".json" { |
| 114 | fmt.Println("Error: Config file must be a .json file") |
| 115 | } |
| 116 | viper.SetConfigFile(configFile) |
| 117 | } else { |
| 118 | viper.AddConfigPath(defaultConfigFileDirectory()) |
| 119 | viper.SetConfigName("cronitor") |
| 120 | } |
| 121 | |
| 122 | // If a config file is found, read it in. |
| 123 | if err := viper.ReadInConfig(); err == nil { |
| 124 | log("Reading config from " + viper.ConfigFileUsed()) |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | func sendPing(endpoint string, uniqueIdentifier string, message string, series string, timestamp float64, duration *float64, exitCode *int, metrics map[string]int, schedule string, group *sync.WaitGroup) { |
| 129 | if group != nil { |
nothing calls this directly
no test coverage detected