LoadConfig loads config from the given file. Panic if failed to load.
(filename string)
| 84 | |
| 85 | // LoadConfig loads config from the given file. Panic if failed to load. |
| 86 | func LoadConfig(filename string) (*Config, error) { |
| 87 | file, err := os.Open(filename) |
| 88 | if err != nil { |
| 89 | return nil, fmt.Errorf("fail to read config file: %w", err) |
| 90 | } |
| 91 | defer file.Close() |
| 92 | |
| 93 | var config Config |
| 94 | err = json.NewDecoder(file).Decode(&config) |
| 95 | if err != nil { |
| 96 | return nil, fmt.Errorf("fail to parse config: %w", err) |
| 97 | } |
| 98 | if config.WorkDir != "" && !filepath.IsAbs(config.WorkDir) { |
| 99 | config.WorkDir, err = filepath.Abs(config.WorkDir) |
| 100 | if err != nil { |
| 101 | return nil, fmt.Errorf("fail to get absolute path of the work directory: %w", err) |
| 102 | } |
| 103 | } |
| 104 | normalizeConfig(&config) |
| 105 | return &config, nil |
| 106 | } |
| 107 | |
| 108 | func DefaultConfig() *Config { |
| 109 | config := &Config{} |
no test coverage detected