Skip to content

Commit 9410002

Browse files
matzewamimof
andauthored
Usage of constants (#31)
* Usage of constants Signed-off-by: Matthias Wessendorf <mwessend@redhat.com> * 💄 run make fmt Signed-off-by: Matthias Wessendorf <mwessend@redhat.com> Co-authored-by: Amir Mofasser <amimof@users.noreply.github.com>
1 parent bc3c602 commit 9410002

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

huego.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ import (
1010
"strings"
1111
)
1212

13+
const (
14+
applicationJSON = "application/json"
15+
contentType = "Content-Type"
16+
)
17+
1318
// APIResponse holds the response data returned form the bridge after a request has been made.
1419
type APIResponse struct {
1520
Success map[string]interface{} `json:"success,omitempty"`
@@ -82,7 +87,7 @@ func unmarshal(data []byte, v interface{}) error {
8287

8388
func get(ctx context.Context, url string) ([]byte, error) {
8489

85-
req, err := http.NewRequest("GET", url, nil)
90+
req, err := http.NewRequest(http.MethodGet, url, nil)
8691
if err != nil {
8792
return nil, err
8893
}
@@ -110,14 +115,14 @@ func put(ctx context.Context, url string, data []byte) ([]byte, error) {
110115

111116
body := strings.NewReader(string(data))
112117

113-
req, err := http.NewRequest("PUT", url, body)
118+
req, err := http.NewRequest(http.MethodPut, url, body)
114119
if err != nil {
115120
return nil, err
116121
}
117122

118123
req = req.WithContext(ctx)
119124

120-
req.Header.Set("Content-Type", "application/json")
125+
req.Header.Set(contentType, applicationJSON)
121126

122127
client := http.Client{}
123128
res, err := client.Do(req)
@@ -140,14 +145,14 @@ func post(ctx context.Context, url string, data []byte) ([]byte, error) {
140145

141146
body := strings.NewReader(string(data))
142147

143-
req, err := http.NewRequest("POST", url, body)
148+
req, err := http.NewRequest(http.MethodPost, url, body)
144149
if err != nil {
145150
return nil, err
146151
}
147152

148153
req = req.WithContext(ctx)
149154

150-
req.Header.Set("Content-Type", "application/json")
155+
req.Header.Set(contentType, applicationJSON)
151156

152157
client := http.Client{}
153158
res, err := client.Do(req)
@@ -168,14 +173,14 @@ func post(ctx context.Context, url string, data []byte) ([]byte, error) {
168173

169174
func delete(ctx context.Context, url string) ([]byte, error) {
170175

171-
req, err := http.NewRequest("DELETE", url, nil)
176+
req, err := http.NewRequest(http.MethodDelete, url, nil)
172177
if err != nil {
173178
return nil, err
174179
}
175180

176181
req = req.WithContext(ctx)
177182

178-
req.Header.Set("Content-Type", "application/json")
183+
req.Header.Set(contentType, applicationJSON)
179184

180185
client := http.Client{}
181186
res, err := client.Do(req)
@@ -204,7 +209,7 @@ func DiscoverAll() ([]Bridge, error) {
204209
// DiscoverAllContext returns a list of Bridge objects.
205210
func DiscoverAllContext(ctx context.Context) ([]Bridge, error) {
206211

207-
req, err := http.NewRequest("GET", "https://discovery.meethue.com", nil)
212+
req, err := http.NewRequest(http.MethodGet, "https://discovery.meethue.com", nil)
208213
if err != nil {
209214
return nil, err
210215
}

0 commit comments

Comments
 (0)