Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
whats-this
api
Commits
978d45c2
Commit
978d45c2
authored
Feb 25, 2019
by
Dean
Browse files
version 1.6.1: fix /users/me to be backwards compatible
parent
bed9a54a
Changes
2
Hide whitespace changes
Inline
Side-by-side
lib/routes/me.go
View file @
978d45c2
...
...
@@ -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
}
)
}
main.go
View file @
978d45c2
...
...
@@ -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{}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment