manager/magefiles/config.go
Dan Anglin 903e5d8b66
checkpoint: manage home directories
- ensure configured home directories are present and their mode set to
  0700
- move dotfiles to files
- added JSON config
2024-09-09 18:02:53 +01:00

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