From ff442486d6099dee4e9a2a5ea3cb0f57abf1b648 Mon Sep 17 00:00:00 2001 From: Tobias Lindberg Date: Fri, 12 Mar 2021 10:58:41 +0100 Subject: [PATCH] using http.Method instead of strings changing http.NewRequest error field to _ adding User-Agent header to http request --- src/v1_TeslaMateAPICarsCommand.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/v1_TeslaMateAPICarsCommand.go b/src/v1_TeslaMateAPICarsCommand.go index ff8995a..be1ff1e 100644 --- a/src/v1_TeslaMateAPICarsCommand.go +++ b/src/v1_TeslaMateAPICarsCommand.go @@ -27,7 +27,7 @@ func TeslaMateAPICarsCommandV1(c *gin.Context) { } // if request method is GET return list of commands - if c.Request.Method == "GET" { + if c.Request.Method == http.MethodGet { c.JSON(http.StatusOK, gin.H{"enabled_commands": allowList}) return } @@ -110,9 +110,10 @@ func TeslaMateAPICarsCommandV1(c *gin.Context) { } client := &http.Client{} - req, err := http.NewRequest("POST", "https://owner-api.teslamotors.com/api/1/vehicles/"+TeslaVehicleID+command, strings.NewReader(string(reqBody))) - req.Header.Add("Authorization", "Bearer "+TeslaAccessToken) - req.Header.Add("Content-Type", "application/json") + req, _ := http.NewRequest(http.MethodPost, "https://owner-api.teslamotors.com/api/1/vehicles/"+TeslaVehicleID+command, strings.NewReader(string(reqBody))) + req.Header.Set("Authorization", "Bearer "+TeslaAccessToken) + req.Header.Set("Content-Type", "application/json") + req.Header.Set("User-Agent", "TeslaMateApi/"+apiVersion+" https://github.com/tobiasehlert/teslamateapi") resp, err := client.Do(req) // check response error