manager/magefiles/config.go

38 lines
627 B
Go
Raw Normal View History

//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
}