go-taskrem/config.go
2022-09-16 20:13:02 +01:00

36 lines
607 B
Go

package main
import (
"encoding/json"
"os"
)
//TODO: Create:
// * LoadConfig
// * CreateSampleConfig
type Config struct {
Tasks []Task
}
// LoadConfig will take in the filename, load the JSON and return a pointer to Config, a slice of Tasks
func LoadConfig(filename string) (*Config, error) {
file, err := os.ReadFile(filename)
if err != nil {
return nil, err //nil is used here as we return a pointer to Config
}
config := &Config{}
err = json.Unmarshal(file, &config)
if err != nil {
return nil, err
}
return config, nil
}
/*
func CreateSampleConfig() (*Config, error) {
return
}
*/