From 978d45c22305f23123fa9418ac7ca9868a655dcc Mon Sep 17 00:00:00 2001 From: Dean Sheather <dean@deansheather.com> Date: Mon, 25 Feb 2019 20:29:04 +1000 Subject: [PATCH] version 1.6.1: fix /users/me to be backwards compatible --- lib/routes/me.go | 26 +++++++++++++++++++++++++- main.go | 2 +- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/routes/me.go b/lib/routes/me.go index 3ce5fe4..3d6f176 100644 --- a/lib/routes/me.go +++ b/lib/routes/me.go @@ -9,6 +9,23 @@ import ( "github.com/go-chi/render" ) +// meResponse is the response type for /users/me. +type meResponse struct { + Success bool `json:"success"` + StatusCode *int `json:"errorcode"` + User meUser `json:"user"` +} + +// meUser is a modified version of db.User for /users/me to maintain +// compatibility with the original version of the route. +type meUser struct { + UserID string `json:"user_id"` + Username string `json:"username"` + Email string `json:"email"` + IsAdmin bool `json:"is_admin"` + IsBlocked bool `json:"is_blocked"` +} + // Me handles /users/me requests. func Me(w http.ResponseWriter, r *http.Request) { // Only authorized users can use this route @@ -18,7 +35,14 @@ func Me(w http.ResponseWriter, r *http.Request) { } // Return response + u := meUser{ + UserID: user.ID, + Username: user.Username, + Email: user.Email, + IsAdmin: user.IsAdmin, + IsBlocked: user.IsBlocked, + } w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) - render.JSON(w, r, user) + render.JSON(w, r, meResponse{true, nil, u}) } diff --git a/main.go b/main.go index 17bde52..1c7102c 100644 --- a/main.go +++ b/main.go @@ -25,7 +25,7 @@ import ( const ( configLocationUnix = "/etc/whats-this/api/config.toml" shutdownTimeout = 10 * time.Second - version = "1.6.0" + version = "1.6.1" ) // printConfiguration iterates through a configuration map[string]interface{} -- GitLab