| 122 | } |
| 123 | |
| 124 | func loadFile(filePath string) (string, Configuration, error) { |
| 125 | f, fErr := os.Open(filePath) |
| 126 | |
| 127 | if fErr != nil { |
| 128 | return fileTypeName, Configuration{}, fErr |
| 129 | } |
| 130 | |
| 131 | defer f.Close() |
| 132 | |
| 133 | cfg := fileCfgCommon{} |
| 134 | |
| 135 | jDecoder := json.NewDecoder(f) |
| 136 | jDecodeErr := jDecoder.Decode(&cfg) |
| 137 | |
| 138 | if jDecodeErr != nil { |
| 139 | return fileTypeName, Configuration{}, jDecodeErr |
| 140 | } |
| 141 | |
| 142 | finalCfg, dialer, cfgErr := cfg.build() |
| 143 | |
| 144 | if cfgErr != nil { |
| 145 | return fileTypeName, Configuration{}, cfgErr |
| 146 | } |
| 147 | |
| 148 | servers := make([]Server, len(finalCfg.Servers)) |
| 149 | |
| 150 | for i := range servers { |
| 151 | servers[i] = finalCfg.Servers[i].build() |
| 152 | } |
| 153 | |
| 154 | return fileTypeName, Configuration{ |
| 155 | HostName: finalCfg.HostName, |
| 156 | SharedKey: finalCfg.SharedKey, |
| 157 | Dialer: dialer, |
| 158 | DialTimeout: time.Duration(finalCfg.DialTimeout) * time.Second, |
| 159 | Servers: servers, |
| 160 | }, nil |
| 161 | } |
| 162 | |
| 163 | // File creates a configuration file loader |
| 164 | func File(customPath string) Loader { |