From aed5503e7b541025481da5e33d16bc821e59045e Mon Sep 17 00:00:00 2001 From: Tobias Lindberg Date: Tue, 2 Mar 2021 13:58:06 +0100 Subject: [PATCH] implementation of versioning in uri updating README with version info --- README.md | 19 ++++---- ...o => V1_TeslaMateAPICarsChargesDetails.go} | 12 ++--- ...aMateAPICars.go => v1_TeslaMateAPICars.go} | 20 ++++---- ...arges.go => v1_TeslaMateAPICarsCharges.go} | 12 ++--- ...Drives.go => v1_TeslaMateAPICarsDrives.go} | 12 ++--- ...go => v1_TeslaMateAPICarsDrivesDetails.go} | 12 ++--- ...Status.go => v1_TeslaMateAPICarsStatus.go} | 18 +++---- ...dates.go => v1_TeslaMateAPICarsUpdates.go} | 12 ++--- ...gs.go => v1_TeslaMateAPIGlobalsettings.go} | 12 ++--- src/webserver.go | 47 +++++++++++-------- 10 files changed, 92 insertions(+), 84 deletions(-) rename src/{TeslaMateAPICarsChargesDetails.go => V1_TeslaMateAPICarsChargesDetails.go} (95%) rename src/{TeslaMateAPICars.go => v1_TeslaMateAPICars.go} (89%) rename src/{TeslaMateAPICarsCharges.go => v1_TeslaMateAPICarsCharges.go} (94%) rename src/{TeslaMateAPICarsDrives.go => v1_TeslaMateAPICarsDrives.go} (96%) rename src/{TeslaMateAPICarsDrivesDetails.go => v1_TeslaMateAPICarsDrivesDetails.go} (97%) rename src/{TeslaMateAPICarsStatus.go => v1_TeslaMateAPICarsStatus.go} (97%) rename src/{TeslaMateAPICarsUpdates.go => v1_TeslaMateAPICarsUpdates.go} (87%) rename src/{TeslaMateAPIGlobalSettings.go => v1_TeslaMateAPIGlobalsettings.go} (90%) diff --git a/README.md b/README.md index 9110772..ff63cad 100644 --- a/README.md +++ b/README.md @@ -113,15 +113,16 @@ Basically the same environment variables for the database, mqqt and timezone nee More detailed documentation of every endpoint will come.. - GET `/` -- GET `/cars` -- GET `/cars/:CarID` -- GET `/cars/:CarID/charges` -- GET `/cars/:CarID/charges/:ChargeID` -- GET `/cars/:CarID/drives` -- GET `/cars/:CarID/drives/:DriveID` -- GET `/cars/:CarID/status` -- GET `/cars/:CarID/updates` -- GET `/globalsettings` +- GET `/v1` +- GET `/v1/cars` +- GET `/v1/cars/:CarID` +- GET `/v1/cars/:CarID/charges` +- GET `/v1/cars/:CarID/charges/:ChargeID` +- GET `/v1/cars/:CarID/drives` +- GET `/v1/cars/:CarID/drives/:DriveID` +- GET `/v1/cars/:CarID/status` +- GET `/v1/cars/:CarID/updates` +- GET `/v1/globalsettings` - GET `/ping` ## Security information diff --git a/src/TeslaMateAPICarsChargesDetails.go b/src/V1_TeslaMateAPICarsChargesDetails.go similarity index 95% rename from src/TeslaMateAPICarsChargesDetails.go rename to src/V1_TeslaMateAPICarsChargesDetails.go index 433eddd..b206627 100644 --- a/src/TeslaMateAPICarsChargesDetails.go +++ b/src/V1_TeslaMateAPICarsChargesDetails.go @@ -9,8 +9,8 @@ import ( _ "github.com/lib/pq" ) -// TeslaMateAPICarsChargesDetails func -func TeslaMateAPICarsChargesDetails(c *gin.Context) { +// TeslaMateAPICarsChargesDetailsV1 func +func TeslaMateAPICarsChargesDetailsV1(c *gin.Context) { // getting CarID and ChargeID param from URL CarID := convertStringToInteger(c.Param("CarID")) @@ -318,17 +318,17 @@ func TeslaMateAPICarsChargesDetails(c *gin.Context) { // print to log about request if gin.IsDebugging() { - log.Printf("[TeslaMateApi] TeslaMateAPICarsChargesDetails returned /cars/%d/charges/%d data:", CarID, ChargeID) + log.Printf("[debug] TeslaMateAPICarsChargesDetailsV1 returned /cars/%d/charges/%d data:", CarID, ChargeID) js, _ := json.Marshal(jsonData) log.Printf("%s\n", js) } // return jsonData if ValidResponse { - log.Printf("[TeslaMateApi] TeslaMateAPICarsChargesDetails executed /cars/%d/charges/%d successful.", CarID, ChargeID) + log.Printf("[info] TeslaMateAPICarsChargesDetailsV1 executed /cars/%d/charges/%d successful.", CarID, ChargeID) c.JSON(http.StatusOK, jsonData) } else { - log.Printf("[TeslaMateApi] TeslaMateAPICarsChargesDetails error in /cars/%d/charges/%d execution!", CarID, ChargeID) - c.JSON(http.StatusNotFound, gin.H{"error": "something went wrong in TeslaMateAPICarsChargesDetails.."}) + log.Printf("[error] TeslaMateAPICarsChargesDetailsV1 error in /cars/%d/charges/%d execution!", CarID, ChargeID) + c.JSON(http.StatusNotFound, gin.H{"error": "something went wrong in TeslaMateAPICarsChargesDetailsV1.."}) } } diff --git a/src/TeslaMateAPICars.go b/src/v1_TeslaMateAPICars.go similarity index 89% rename from src/TeslaMateAPICars.go rename to src/v1_TeslaMateAPICars.go index 27b1118..3d79d7a 100644 --- a/src/TeslaMateAPICars.go +++ b/src/v1_TeslaMateAPICars.go @@ -9,8 +9,8 @@ import ( _ "github.com/lib/pq" ) -// TeslaMateAPICars func -func TeslaMateAPICars(c *gin.Context) { +// TeslaMateAPICarsV1 func +func TeslaMateAPICarsV1(c *gin.Context) { // getting CarID param from URL ParamCarID := c.Param("CarID") @@ -179,9 +179,9 @@ func TeslaMateAPICars(c *gin.Context) { // print to log about request if gin.IsDebugging() && ValidResponse { if CarID > 0 { - log.Printf("[TeslaMateApi] TeslaMateAPICars returned /cars/%d data:", CarID) + log.Printf("[debug] TeslaMateAPICarsV1 returned /cars/%d data:", CarID) } else { - log.Println("[TeslaMateApi] TeslaMateAPICars returned /cars data:") + log.Println("[debug] TeslaMateAPICarsV1 returned /cars data:") } js, _ := json.Marshal(jsonData) log.Printf("%s\n", js) @@ -190,20 +190,20 @@ func TeslaMateAPICars(c *gin.Context) { // return jsonData if ValidResponse { if CarID > 0 { - log.Printf("[TeslaMateApi] TeslaMateAPICars executed /cars/%d successful.", CarID) + log.Printf("[info] TeslaMateAPICarsV1 executed /cars/%d successful.", CarID) } else { - log.Println("[TeslaMateApi] TeslaMateAPICars executed /cars successful.") + log.Println("[info] TeslaMateAPICarsV1 executed /cars successful.") } c.JSON(http.StatusOK, jsonData) } else { if CarID > 0 { - log.Printf("[TeslaMateApi] TeslaMateAPICars error in /cars/%d execution!", CarID) + log.Printf("[error] TeslaMateAPICarsV1 error in /cars/%d execution!", CarID) } else if len(ParamCarID) > 0 { - log.Printf("[TeslaMateApi] TeslaMateAPICars error in /cars/%s execution!", ParamCarID) + log.Printf("[error] TeslaMateAPICarsV1 error in /cars/%s execution!", ParamCarID) } else { - log.Println("[TeslaMateApi] TeslaMateAPICars error in /cars execution!") + log.Println("[error] TeslaMateAPICarsV1 error in /cars execution!") } - c.JSON(http.StatusNotFound, gin.H{"error": "something went wrong in TeslaMateAPICars.."}) + c.JSON(http.StatusNotFound, gin.H{"error": "something went wrong in TeslaMateAPICarsV1.."}) } } diff --git a/src/TeslaMateAPICarsCharges.go b/src/v1_TeslaMateAPICarsCharges.go similarity index 94% rename from src/TeslaMateAPICarsCharges.go rename to src/v1_TeslaMateAPICarsCharges.go index 7907390..0558685 100644 --- a/src/TeslaMateAPICarsCharges.go +++ b/src/v1_TeslaMateAPICarsCharges.go @@ -9,8 +9,8 @@ import ( _ "github.com/lib/pq" ) -// TeslaMateAPICarsCharges func -func TeslaMateAPICarsCharges(c *gin.Context) { +// TeslaMateAPICarsChargesV1 func +func TeslaMateAPICarsChargesV1(c *gin.Context) { // getting CarID param from URL CarID := convertStringToInteger(c.Param("CarID")) @@ -198,17 +198,17 @@ func TeslaMateAPICarsCharges(c *gin.Context) { // print to log about request if gin.IsDebugging() { - log.Printf("[TeslaMateApi] TeslaMateAPICarsCharges returned /cars/%d/charges data:", CarID) + log.Printf("[debug] TeslaMateAPICarsChargesV1 returned /cars/%d/charges data:", CarID) js, _ := json.Marshal(jsonData) log.Printf("%s\n", js) } // return jsonData if ValidResponse { - log.Printf("[TeslaMateApi] TeslaMateAPICarsCharges executed /cars/%d/charges successful.", CarID) + log.Printf("[info] TeslaMateAPICarsChargesV1 executed /cars/%d/charges successful.", CarID) c.JSON(http.StatusOK, jsonData) } else { - log.Printf("[TeslaMateApi] TeslaMateAPICarsCharges error in /cars/%d/charges execution!", CarID) - c.JSON(http.StatusNotFound, gin.H{"error": "something went wrong in TeslaMateAPICarsCharges.."}) + log.Printf("[error] TeslaMateAPICarsChargesV1 error in /cars/%d/charges execution!", CarID) + c.JSON(http.StatusNotFound, gin.H{"error": "something went wrong in TeslaMateAPICarsChargesV1.."}) } } diff --git a/src/TeslaMateAPICarsDrives.go b/src/v1_TeslaMateAPICarsDrives.go similarity index 96% rename from src/TeslaMateAPICarsDrives.go rename to src/v1_TeslaMateAPICarsDrives.go index e00bc9d..df419cd 100644 --- a/src/TeslaMateAPICarsDrives.go +++ b/src/v1_TeslaMateAPICarsDrives.go @@ -9,8 +9,8 @@ import ( _ "github.com/lib/pq" ) -// TeslaMateAPICarsDrives func -func TeslaMateAPICarsDrives(c *gin.Context) { +// TeslaMateAPICarsDrivesV1 func +func TeslaMateAPICarsDrivesV1(c *gin.Context) { // getting CarID param from URL CarID := convertStringToInteger(c.Param("CarID")) @@ -246,17 +246,17 @@ func TeslaMateAPICarsDrives(c *gin.Context) { // print to log about request if gin.IsDebugging() { - log.Printf("[TeslaMateApi] TeslaMateAPICarsDrives returned /cars/%d/drives data:", CarID) + log.Printf("[debug] TeslaMateAPICarsDrivesV1 returned /cars/%d/drives data:", CarID) js, _ := json.Marshal(jsonData) log.Printf("%s\n", js) } // return jsonData if ValidResponse { - log.Printf("[TeslaMateApi] TeslaMateAPICarsDrives executed /cars/%d/drives successful.", CarID) + log.Printf("[info] TeslaMateAPICarsDrivesV1 executed /cars/%d/drives successful.", CarID) c.JSON(http.StatusOK, jsonData) } else { - log.Printf("[TeslaMateApi] TeslaMateAPICarsDrives error in /cars/%d/drives execution!", CarID) - c.JSON(http.StatusNotFound, gin.H{"error": "something went wrong in TeslaMateAPICarsDrives.."}) + log.Printf("[error] TeslaMateAPICarsDrivesV1 error in /cars/%d/drives execution!", CarID) + c.JSON(http.StatusNotFound, gin.H{"error": "something went wrong in TeslaMateAPICarsDrivesV1.."}) } } diff --git a/src/TeslaMateAPICarsDrivesDetails.go b/src/v1_TeslaMateAPICarsDrivesDetails.go similarity index 97% rename from src/TeslaMateAPICarsDrivesDetails.go rename to src/v1_TeslaMateAPICarsDrivesDetails.go index c2b3691..c58d38a 100644 --- a/src/TeslaMateAPICarsDrivesDetails.go +++ b/src/v1_TeslaMateAPICarsDrivesDetails.go @@ -9,8 +9,8 @@ import ( _ "github.com/lib/pq" ) -// TeslaMateAPICarsDrivesDetails func -func TeslaMateAPICarsDrivesDetails(c *gin.Context) { +// TeslaMateAPICarsDrivesDetailsV1 func +func TeslaMateAPICarsDrivesDetailsV1(c *gin.Context) { // getting CarID and DriveID param from URL CarID := convertStringToInteger(c.Param("CarID")) @@ -381,17 +381,17 @@ func TeslaMateAPICarsDrivesDetails(c *gin.Context) { // print to log about request if gin.IsDebugging() { - log.Printf("[TeslaMateApi] TeslaMateAPICarsDrivesDetails returned /cars/%d/drives/%d data:", CarID, DriveID) + log.Printf("[debug] TeslaMateAPICarsDrivesDetailsV1 returned /cars/%d/drives/%d data:", CarID, DriveID) js, _ := json.Marshal(jsonData) log.Printf("%s\n", js) } // return jsonData if ValidResponse { - log.Printf("[TeslaMateApi] TeslaMateAPICarsDrivesDetails executed /cars/%d/drives/%d successful.", CarID, DriveID) + log.Printf("[info] TeslaMateAPICarsDrivesDetailsV1 executed /cars/%d/drives/%d successful.", CarID, DriveID) c.JSON(http.StatusOK, jsonData) } else { - log.Printf("[TeslaMateApi] TeslaMateAPICarsDrivesDetails error in /cars/%d/drives/%d execution!", CarID, DriveID) - c.JSON(http.StatusNotFound, gin.H{"error": "something went wrong in TeslaMateAPICarsDrivesDetails.."}) + log.Printf("[error] TeslaMateAPICarsDrivesDetailsV1 error in /cars/%d/drives/%d execution!", CarID, DriveID) + c.JSON(http.StatusNotFound, gin.H{"error": "something went wrong in TeslaMateAPICarsDrivesDetailsV1.."}) } } diff --git a/src/TeslaMateAPICarsStatus.go b/src/v1_TeslaMateAPICarsStatus.go similarity index 97% rename from src/TeslaMateAPICarsStatus.go rename to src/v1_TeslaMateAPICarsStatus.go index d0723c1..7599969 100644 --- a/src/TeslaMateAPICarsStatus.go +++ b/src/v1_TeslaMateAPICarsStatus.go @@ -163,18 +163,18 @@ var f mqtt.MessageHandler = func(client mqtt.Client, msg mqtt.Message) { } else if MqttTopic == "time_to_full_charge" { MQTTDataTimeToFullCharge = convertStringToFloat(string(msg.Payload())) } else { - log.Printf("Error: extraction of data for %s not implemented in mqtt.MessageHandler yet.", MqttTopic) + log.Printf("[warning] mqtt.MessageHandler issue.. extraction of data for %s not implemented!", MqttTopic) } } -// TeslaMateAPICarsStatus func -func TeslaMateAPICarsStatus(c *gin.Context) { +// TeslaMateAPICarsStatusV1 func +func TeslaMateAPICarsStatusV1(c *gin.Context) { // getting mqtt flag mqttdisabled := getEnvAsBool("DISABLE_MQTT", false) if mqttdisabled { - log.Println("[TeslaMateAPICars] DISABLE_MQTT is set to true.. can not return status for car without mqtt!") + log.Println("[notice] TeslaMateAPICarsStatusV1 DISABLE_MQTT is set to true.. can not return status for car without mqtt!") c.JSON(http.StatusNotImplemented, gin.H{"error": "mqtt disabled.. status not accessible!"}) return } @@ -243,7 +243,7 @@ func TeslaMateAPICarsStatus(c *gin.Context) { // showing mqtt successfully connected if gin.IsDebugging() { - log.Println("[TeslaMateApi] TeslaMateAPICarsStatus successfully connected to mqtt.") + log.Println("TeslaMateAPICarsStatus successfully connected to mqtt.") } // creating structs for /cars @@ -548,17 +548,17 @@ func TeslaMateAPICarsStatus(c *gin.Context) { // print to log about request if gin.IsDebugging() { - log.Printf("[TeslaMateApi] TeslaMateAPICarsStatus returned /cars/%d/status data:", CarID) + log.Printf("[debug] TeslaMateAPICarsStatusV1 returned /cars/%d/status data:", CarID) js, _ := json.Marshal(jsonData) log.Printf("%s\n", js) } // return jsonData if ValidResponse { - log.Printf("[TeslaMateApi] TeslaMateAPICarsStatus executed /cars/%d/status successful.", CarID) + log.Printf("[info] TeslaMateAPICarsStatusV1 executed /cars/%d/status successful.", CarID) c.JSON(http.StatusOK, jsonData) } else { - log.Printf("[TeslaMateApi] TeslaMateAPICarsStatus error in /cars/%d/status execution!", CarID) - c.JSON(http.StatusNotFound, gin.H{"error": "something went wrong in TeslaMateAPICarsStatus.."}) + log.Printf("[error] TeslaMateAPICarsStatusV1 error in /cars/%d/status execution!", CarID) + c.JSON(http.StatusNotFound, gin.H{"error": "something went wrong in TeslaMateAPICarsStatusV1.."}) } } diff --git a/src/TeslaMateAPICarsUpdates.go b/src/v1_TeslaMateAPICarsUpdates.go similarity index 87% rename from src/TeslaMateAPICarsUpdates.go rename to src/v1_TeslaMateAPICarsUpdates.go index 0f8d95b..38461dd 100644 --- a/src/TeslaMateAPICarsUpdates.go +++ b/src/v1_TeslaMateAPICarsUpdates.go @@ -9,8 +9,8 @@ import ( _ "github.com/lib/pq" ) -// TeslaMateAPICarsUpdates func -func TeslaMateAPICarsUpdates(c *gin.Context) { +// TeslaMateAPICarsUpdatesV1 func +func TeslaMateAPICarsUpdatesV1(c *gin.Context) { // getting CarID param from URL CarID := convertStringToInteger(c.Param("CarID")) @@ -124,17 +124,17 @@ func TeslaMateAPICarsUpdates(c *gin.Context) { // print to log about request if gin.IsDebugging() { - log.Printf("[TeslaMateApi] TeslaMateAPICarsUpdates returned /cars/%d/updates data:", CarID) + log.Printf("[debug] TeslaMateAPICarsUpdatesV1 returned /cars/%d/updates data:", CarID) js, _ := json.Marshal(jsonData) log.Printf("%s\n", js) } // return jsonData if ValidResponse { - log.Printf("[TeslaMateApi] TeslaMateAPICarsUpdates executed /cars/%d/updates successful.", CarID) + log.Printf("[info] TeslaMateAPICarsUpdatesV1 executed /cars/%d/updates successful.", CarID) c.JSON(http.StatusOK, jsonData) } else { - log.Printf("[TeslaMateApi] TeslaMateAPICarsUpdates error in /cars/%d/updates execution!", CarID) - c.JSON(http.StatusNotFound, gin.H{"error": "something went wrong in TeslaMateAPICarsUpdates.."}) + log.Printf("[error] TeslaMateAPICarsUpdatesV1 error in /cars/%d/updates execution!", CarID) + c.JSON(http.StatusNotFound, gin.H{"error": "something went wrong in TeslaMateAPICarsUpdatesV1.."}) } } diff --git a/src/TeslaMateAPIGlobalSettings.go b/src/v1_TeslaMateAPIGlobalsettings.go similarity index 90% rename from src/TeslaMateAPIGlobalSettings.go rename to src/v1_TeslaMateAPIGlobalsettings.go index ec7fc04..269bcf7 100644 --- a/src/TeslaMateAPIGlobalSettings.go +++ b/src/v1_TeslaMateAPIGlobalsettings.go @@ -9,8 +9,8 @@ import ( _ "github.com/lib/pq" ) -// TeslaMateAPIGlobalsettings func -func TeslaMateAPIGlobalsettings(c *gin.Context) { +// TeslaMateAPIGlobalsettingsV1 func +func TeslaMateAPIGlobalsettingsV1(c *gin.Context) { // creating structs for /globalsettings // AccountInfo struct - child of GlobalSettings @@ -127,17 +127,17 @@ func TeslaMateAPIGlobalsettings(c *gin.Context) { // print to log about request if gin.IsDebugging() { - log.Println("[TeslaMateApi] TeslaMateAPIGlobalsettings returned /cars data:") + log.Println("[debug] TeslaMateAPIGlobalsettingsV1 returned /cars data:") js, _ := json.Marshal(jsonData) log.Printf("%s\n", js) } // return jsonData if ValidResponse { - log.Println("[TeslaMateApi] TeslaMateAPIGlobalsettings executed /cars successful.") + log.Println("[info] TeslaMateAPIGlobalsettingsV1 executed /cars successful.") c.JSON(http.StatusOK, jsonData) } else { - log.Println("[TeslaMateApi] TeslaMateAPIGlobalsettings error in /cars execution!") - c.JSON(http.StatusNotFound, gin.H{"error": "something went wrong in TeslaMateAPIGlobalsettings.."}) + log.Println("[error] TeslaMateAPIGlobalsettingsV1 error in /cars execution!") + c.JSON(http.StatusNotFound, gin.H{"error": "something went wrong in TeslaMateAPIGlobalsettingsV1.."}) } } diff --git a/src/webserver.go b/src/webserver.go index c9858f8..69945d5 100644 --- a/src/webserver.go +++ b/src/webserver.go @@ -35,29 +35,36 @@ func main() { r := gin.Default() // root endpoint telling API is running - r.GET("/", func(c *gin.Context) { - c.JSON(http.StatusOK, gin.H{ - "message": "TeslaMateApi runnnig..", - }) - }) + r.GET("/", func(c *gin.Context) { c.JSON(http.StatusOK, gin.H{"message": "TeslaMateApi container runnnig.."}) }) - // TeslaMateApi endpoints - r.GET("/cars", TeslaMateAPICars) - r.GET("/cars/:CarID", TeslaMateAPICars) - r.GET("/cars/:CarID/charges", TeslaMateAPICarsCharges) - r.GET("/cars/:CarID/charges/:ChargeID", TeslaMateAPICarsChargesDetails) - r.GET("/cars/:CarID/drives", TeslaMateAPICarsDrives) - r.GET("/cars/:CarID/drives/:DriveID", TeslaMateAPICarsDrivesDetails) - r.GET("/cars/:CarID/status", TeslaMateAPICarsStatus) - r.GET("/cars/:CarID/updates", TeslaMateAPICarsUpdates) - r.GET("/globalsettings", TeslaMateAPIGlobalsettings) + // TeslaMateApi v1 endpoints + v1 := r.Group("/v1") + { + v1.GET("/", func(c *gin.Context) { c.JSON(http.StatusOK, gin.H{"message": "TeslaMateApi v1 runnnig.."}) }) + v1.GET("/cars", TeslaMateAPICarsV1) + v1.GET("/cars/:CarID", TeslaMateAPICarsV1) + v1.GET("/cars/:CarID/charges", TeslaMateAPICarsChargesV1) + v1.GET("/cars/:CarID/charges/:ChargeID", TeslaMateAPICarsChargesDetailsV1) + v1.GET("/cars/:CarID/drives", TeslaMateAPICarsDrivesV1) + v1.GET("/cars/:CarID/drives/:DriveID", TeslaMateAPICarsDrivesDetailsV1) + v1.GET("/cars/:CarID/status", TeslaMateAPICarsStatusV1) + v1.GET("/cars/:CarID/updates", TeslaMateAPICarsUpdatesV1) + v1.GET("/globalsettings", TeslaMateAPIGlobalsettingsV1) + } + + // TeslaMateApi endpoints (bofore versioning) + r.GET("/cars", func(c *gin.Context) { c.Redirect(http.StatusMovedPermanently, "/v1"+c.Request.RequestURI) }) + r.GET("/cars/:CarID", func(c *gin.Context) { c.Redirect(http.StatusMovedPermanently, "/v1"+c.Request.RequestURI) }) + r.GET("/cars/:CarID/charges", func(c *gin.Context) { c.Redirect(http.StatusMovedPermanently, "/v1"+c.Request.RequestURI) }) + r.GET("/cars/:CarID/charges/:ChargeID", func(c *gin.Context) { c.Redirect(http.StatusMovedPermanently, "/v1"+c.Request.RequestURI) }) + r.GET("/cars/:CarID/drives", func(c *gin.Context) { c.Redirect(http.StatusMovedPermanently, "/v1"+c.Request.RequestURI) }) + r.GET("/cars/:CarID/drives/:DriveID", func(c *gin.Context) { c.Redirect(http.StatusMovedPermanently, "/v1"+c.Request.RequestURI) }) + r.GET("/cars/:CarID/status", func(c *gin.Context) { c.Redirect(http.StatusMovedPermanently, "/v1"+c.Request.RequestURI) }) + r.GET("/cars/:CarID/updates", func(c *gin.Context) { c.Redirect(http.StatusMovedPermanently, "/v1"+c.Request.RequestURI) }) + r.GET("/globalsettings", func(c *gin.Context) { c.Redirect(http.StatusMovedPermanently, "/v1"+c.Request.RequestURI) }) // /ping endpoint - r.GET("/ping", func(c *gin.Context) { - c.JSON(http.StatusOK, gin.H{ - "message": "pong", - }) - }) + r.GET("/ping", func(c *gin.Context) { c.JSON(http.StatusOK, gin.H{"message": "pong"}) }) // run this and serve on 0.0.0.0:8080 r.Run(":8080")