38 lines
627 B
Go
38 lines
627 B
Go
|
//go:build mage
|
||
|
|
||
|
package main
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"fmt"
|
||
|
"os"
|
||
|
"path/filepath"
|
||
|
)
|
||
|
|
||
|
const (
|
||
|
configDir string = "./config/"
|
||
|
configFileName string = "config.json"
|
||
|
)
|
||
|
|
||
|
type config struct {
|
||
|
Directories []string `json:"directories"`
|
||
|
}
|
||
|
|
||
|
func newConfig() (config, error) {
|
||
|
var cfg config
|
||
|
|
||
|
path := filepath.Join(configDir, configFileName)
|
||
|
|
||
|
file, err := os.Open(path)
|
||
|
if err != nil {
|
||
|
return cfg, fmt.Errorf("unable to open the file: %w", err)
|
||
|
}
|
||
|
defer file.Close()
|
||
|
|
||
|
if err = json.NewDecoder(file).Decode(&cfg); err != nil {
|
||
|
return cfg, fmt.Errorf("unable to decode the JSON file: %w", err)
|
||
|
}
|
||
|
|
||
|
return cfg, nil
|
||
|
}
|