mirror of
https://github.com/gosticks/go-hue-interface.git
synced 2025-10-16 11:45:35 +00:00
bla
This commit is contained in:
parent
178bcba23b
commit
9019b30330
32
config.go
32
config.go
@ -1,7 +1,39 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
// Config hue api config
|
// Config hue api config
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Username string `yaml:name`
|
Username string `yaml:name`
|
||||||
Password string `yaml:userpassword`
|
Password string `yaml:userpassword`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// createNewUser will create a new user. This should be called only of there's none in the yaml config.
|
||||||
|
func (c *Config) createNewUser() {
|
||||||
|
// TODO: read/create the url
|
||||||
|
url := "http://192.168.178.46/api"
|
||||||
|
|
||||||
|
var reqBody = []byte(`{"devicetype": "go-hue-interface#Philips hue"}`)
|
||||||
|
req, err := http.NewRequest("POST", url, bytes.NewBuffer(reqBody))
|
||||||
|
|
||||||
|
client := &http.Client{}
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
fmt.Println("response Status:", resp.Status)
|
||||||
|
fmt.Println("response Headers:", resp.Header)
|
||||||
|
body, _ := ioutil.ReadAll(resp.Body)
|
||||||
|
fmt.Println("response Body:", string(body))
|
||||||
|
|
||||||
|
json.Unmarshal([]byte(str), &res)
|
||||||
|
fmt.Println(res)
|
||||||
|
fmt.Println(res.Fruits[0])
|
||||||
|
}
|
||||||
|
|||||||
3
config.yaml
Normal file
3
config.yaml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
DeviceAddr: "192.168.178.46"
|
||||||
|
User: "nX1ye7AMQoQswiiJdxyw-92-RNhIwicXiQRg7AtF"
|
||||||
|
UserKey: ""
|
||||||
Loading…
Reference in New Issue
Block a user