lockserver/config/config.go
Finn a5433beca0
Some checks failed
/ build-container (push) Has been cancelled
change default port to match what HA expects
2024-04-23 23:06:16 -07:00

52 lines
896 B
Go

package config
import (
"encoding/json"
"errors"
"os"
"github.com/sirupsen/logrus"
)
type Config struct {
ZWaveJSServer string `json:"zwave-js-server"`
SqliteDatabase string `json:"sqlite-database"`
HTTPBind string `json:"http-bind"`
}
var C = Config{
ZWaveJSServer: "ws://addon_core_zwave_js:3000",
SqliteDatabase: "/data/lockserver.db",
HTTPBind: ":8099",
}
var configFiles = []string{"lockserver.json", "/etc/lockserver.json"}
func Load() error {
for _, path := range configFiles {
err := load(path)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
continue
}
return err
}
logrus.WithField("file", path).Info("loaded config")
}
return nil
}
func load(path string) error {
f, err := os.Open(path)
if err != nil {
return err
}
defer f.Close()
if err := json.NewDecoder(f).Decode(&C); err != nil {
return err
}
return nil
}