Skip to content

Commit a856e4e

Browse files
committed
feat(config)!: migrate to YAML config format and load from config.yml
BREAKING CHANGE: Configuration is now stored in `config.yml` using YAML syntax instead of `config.json`.
1 parent 2b440db commit a856e4e

5 files changed

Lines changed: 16 additions & 9 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
config.json
1+
config.yml
22
*.exe
33
*.syso

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Download the [latest release](https://github.com/kh4f/amdalert/releases/latest)
3030
## 🕹️ Usage
3131

3232
- Control the app via CLI (`AMDAlert.exe`).
33-
- Configuration is stored in `config.json` (created automatically on first run). You can edit it manually or via CLI commands.
33+
- Configuration is stored in `config.yaml` (created automatically on first run). You can edit it manually or via CLI commands.
3434
- Enabling alerts starts a background service (`AMDAlertDaemon.exe`) that checks the GPU state every 10 sec and shows notifications when needed.
3535

3636
</br>

go.mod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ module amdalert
22

33
go 1.26.0
44

5-
require golang.org/x/sys v0.42.0
5+
require (
6+
golang.org/x/sys v0.42.0
7+
gopkg.in/yaml.v3 v3.0.1
8+
)

go.sum

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo=
22
golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
3+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
4+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
5+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

internal/config/config.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
package config
22

33
import (
4-
"encoding/json"
54
"os"
65
"time"
6+
7+
"gopkg.in/yaml.v3"
78
)
89

9-
const filePath = "config.json"
10+
const filePath = "config.yml"
1011

1112
type Config struct {
12-
AlertTemp int `json:"alertTemp"`
13-
FanOffAlertTemp int `json:"fanOffAlertTemp"`
13+
AlertTemp int `yaml:"alertTemp"`
14+
FanOffAlertTemp int `yaml:"fanOffAlertTemp"`
1415
}
1516

1617
var (
@@ -31,7 +32,7 @@ func Load() error {
3132
}
3233

3334
loaded := Current
34-
if err := json.Unmarshal(data, &loaded); err != nil {
35+
if err := yaml.Unmarshal(data, &loaded); err != nil {
3536
return err
3637
}
3738

@@ -46,7 +47,7 @@ func Load() error {
4647
}
4748

4849
func Save() error {
49-
data, err := json.MarshalIndent(Current, "", " ")
50+
data, err := yaml.Marshal(Current)
5051
if err != nil {
5152
return err
5253
}

0 commit comments

Comments
 (0)