Load reads the given configuration file, then parses and returns it as a Config.
(fname string)
| 267 | |
| 268 | // Load reads the given configuration file, then parses and returns it as a Config. |
| 269 | func Load(fname string) (*Config, error) { |
| 270 | if fname == "" { |
| 271 | fname = FileName |
| 272 | } |
| 273 | cfg, err := ini.Load(fname) |
| 274 | if err != nil { |
| 275 | return nil, err |
| 276 | } |
| 277 | |
| 278 | // Parse INI file |
| 279 | uc := &Config{} |
| 280 | err = cfg.MapTo(uc) |
| 281 | if err != nil { |
| 282 | return nil, err |
| 283 | } |
| 284 | |
| 285 | // Do any transformations |
| 286 | u, err := url.Parse(uc.App.Host) |
| 287 | if err != nil { |
| 288 | return nil, err |
| 289 | } |
| 290 | d, err := idna.ToASCII(u.Hostname()) |
| 291 | if err != nil { |
| 292 | log.Error("idna.ToASCII for %s: %s", u.Hostname(), err) |
| 293 | return nil, err |
| 294 | } |
| 295 | uc.App.Host = u.Scheme + "://" + d |
| 296 | if u.Port() != "" { |
| 297 | uc.App.Host += ":" + u.Port() |
| 298 | } |
| 299 | |
| 300 | return uc, nil |
| 301 | } |
| 302 | |
| 303 | // Save writes the given Config to the given file. |
| 304 | func Save(uc *Config, fname string) error { |
no outgoing calls
no test coverage detected