Pass parameters directly instead of through a config struct

This commit is contained in:
2022-11-18 20:09:52 +01:00
parent 2df59cdb17
commit 6368fce40d
9 changed files with 53 additions and 76 deletions

View File

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

View File

@@ -37,8 +37,8 @@ func (hue *Hue) SetFlag(id int, value bool) {
}
}
func Connect(config Config) Hue {
hue := Hue{ip: config.IP, login: config.Token, Events: make(chan *sse.Event)}
func New(ip string, token string) *Hue {
hue := Hue{ip: ip, login: token, Events: make(chan *sse.Event)}
// Subscribe to eventstream
client := sse.NewClient(fmt.Sprintf("https://%s/eventstream/clip/v2", hue.ip))
@@ -52,5 +52,5 @@ func Connect(config Config) Hue {
panic(err)
}
return hue
return &hue
}