fleet/server/service/transport_users.go

63 lines
1.5 KiB
Go
Raw Normal View History

2016-09-26 18:48:55 +00:00
package service
2016-08-28 03:59:17 +00:00
import (
"encoding/json"
"net/http"
"golang.org/x/net/context"
)
func decodeCreateUserRequest(ctx context.Context, r *http.Request) (interface{}, error) {
2016-08-28 03:59:17 +00:00
var req createUserRequest
if err := json.NewDecoder(r.Body).Decode(&req.payload); err != nil {
return nil, err
}
return req, nil
}
func decodeGetUserRequest(ctx context.Context, r *http.Request) (interface{}, error) {
id, err := idFromRequest(r, "id")
if err != nil {
return nil, err
2016-08-28 03:59:17 +00:00
}
return getUserRequest{ID: id}, nil
}
func decodeChangePasswordRequest(ctx context.Context, r *http.Request) (interface{}, error) {
var req resetPasswordRequest
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
return nil, err
}
return req, nil
2016-08-28 03:59:17 +00:00
}
func decodeModifyUserRequest(ctx context.Context, r *http.Request) (interface{}, error) {
id, err := idFromRequest(r, "id")
if err != nil {
return nil, err
}
var req modifyUserRequest
if err := json.NewDecoder(r.Body).Decode(&req.payload); err != nil {
return nil, err
}
req.ID = id
return req, nil
}
func decodeForgotPasswordRequest(ctx context.Context, r *http.Request) (interface{}, error) {
var req forgotPasswordRequest
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
return nil, err
}
return req, nil
}
func decodeResetPasswordRequest(ctx context.Context, r *http.Request) (interface{}, error) {
var req resetPasswordRequest
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
2016-08-28 03:59:17 +00:00
return nil, err
}
return req, nil
}