go-taskrem/config.go

36 lines
607 B
Go
Raw Permalink Normal View History

2022-09-05 22:24:44 +01:00
package main
import (
"encoding/json"
"os"
)
//TODO: Create:
// * LoadConfig
// * CreateSampleConfig
type Config struct {
Tasks []Task
}
2022-09-16 13:04:30 +01:00
// LoadConfig will take in the filename, load the JSON and return a pointer to Config, a slice of Tasks
2022-09-05 22:24:44 +01:00
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
}
2022-09-16 20:13:02 +01:00
/*
func CreateSampleConfig() (*Config, error) {
return
}
*/