You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
527 B
30 lines
527 B
2 years ago
|
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
|
||
|
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
|
||
|
}
|