-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.go
More file actions
40 lines (35 loc) · 960 Bytes
/
Copy pathutils.go
File metadata and controls
40 lines (35 loc) · 960 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"encoding/json"
"os"
)
// loadConfig loads configuration from config.json file or creates default config
func loadConfig() error {
file, err := os.Open("config.json")
if err != nil {
// Create default config if it doesn't exist
config = Config{
OpenAIBaseURL: "https://api.openai.com",
OpenAIModel: "gpt-4o-mini",
OpenAIAPIKey: "",
IndoorDeviceModel: "LaCrosse-TX141W",
OutdoorDeviceModel: "LaCrosse-TX141W",
RecommendationIntervalMinutes: 15,
}
return nil
}
defer file.Close()
decoder := json.NewDecoder(file)
return decoder.Decode(&config)
}
// saveConfig saves the current configuration to config.json file
func saveConfig() error {
file, err := os.Create("config.json")
if err != nil {
return err
}
defer file.Close()
encoder := json.NewEncoder(file)
encoder.SetIndent("", " ")
return encoder.Encode(&config)
}