Dan Anglin
903e5d8b66
- ensure configured home directories are present and their mode set to 0700 - move dotfiles to files - added JSON config
37 lines
627 B
Go
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
|
|
}
|