mirror of
https://github.com/NotAShelf/batmon.git
synced 2024-11-26 07:06:46 +00:00
30 lines
575 B
Go
30 lines
575 B
Go
package config
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
|
|
"gomon/internal/logger"
|
|
"gomon/internal/model"
|
|
)
|
|
|
|
// Load loads the battery configuration from a file.
|
|
func Load(filename string) (model.BatteryConfig, error) {
|
|
file, err := os.Open(filename)
|
|
if err != nil {
|
|
logger.Error("Failed to open file")
|
|
return model.BatteryConfig{}, err
|
|
}
|
|
defer file.Close()
|
|
|
|
var config model.BatteryConfig
|
|
decoder := json.NewDecoder(file)
|
|
err = decoder.Decode(&config)
|
|
if err != nil {
|
|
logger.Error("Failed to decode JSON")
|
|
return model.BatteryConfig{}, err
|
|
}
|
|
|
|
return config, nil
|
|
}
|