Implemented better config system
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-11-16 05:20:59 +01:00
parent 644f038732
commit 9f4be2d76e
12 changed files with 135 additions and 875 deletions

View File

@@ -0,0 +1,6 @@
package hue
type Config struct {
Token string `yaml:"token" envconfig:"HUE_TOKEN"`
IP string `yaml:"ip" envconfig:"HUE_IP"`
}

View File

@@ -5,7 +5,6 @@ import (
"crypto/tls"
"fmt"
"net/http"
"os"
"github.com/r3labs/sse/v2"
)
@@ -38,11 +37,8 @@ func (hue *Hue) SetFlag(id int, value bool) {
}
}
func Connect() Hue {
login, _ := os.LookupEnv("HUE_BRIDGE")
ip, _ := os.LookupEnv("HUE_IP")
hue := Hue{ip: ip, login: login, Events: make(chan *sse.Event)}
func Connect(config Config) Hue {
hue := Hue{ip: config.IP, login: config.Token, Events: make(chan *sse.Event)}
// Subscribe to eventstream
client := sse.NewClient(fmt.Sprintf("https://%s/eventstream/clip/v2", hue.ip))