mirror of
https://github.com/gosticks/go-hue-interface.git
synced 2025-10-16 11:45:35 +00:00
add post to bridge method
This commit is contained in:
parent
815895eca7
commit
6c95d8cee4
10
bridge.go
10
bridge.go
@ -6,6 +6,7 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Bridge is the hue bridge interface
|
||||
type Bridge struct {
|
||||
Config *Config
|
||||
}
|
||||
@ -15,16 +16,21 @@ func (b *Bridge) postToBridge(endpoint string, payload interface{}) (interface{}
|
||||
if errMarhshal != nil {
|
||||
return nil, errMarhshal
|
||||
}
|
||||
|
||||
req, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(data))
|
||||
uri := b.getBridgeAPIURI() + endpoint
|
||||
req, err := http.NewRequest(http.MethodPost, uri, bytes.NewBuffer(data))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
client := &http.Client{}
|
||||
res, err := client.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (b *Bridge) getBridgeAPIURI() string {
|
||||
return b.Config.BridgeAddrScheme + "://" + b.Config.BridgeAddr + "/api/" + b.Config.Username
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user