fleet/server/service/transport_invites.go
2016-12-29 20:58:12 -05:00

48 lines
1.1 KiB
Go

package service
import (
"encoding/json"
"net/http"
"strings"
"github.com/gorilla/mux"
"golang.org/x/net/context"
)
func decodeCreateInviteRequest(ctx context.Context, r *http.Request) (interface{}, error) {
var req createInviteRequest
if err := json.NewDecoder(r.Body).Decode(&req.payload); err != nil {
return nil, err
}
if req.payload.Email != nil {
*req.payload.Email = strings.ToLower(*req.payload.Email)
}
return req, nil
}
func decodeDeleteInviteRequest(ctx context.Context, r *http.Request) (interface{}, error) {
id, err := idFromRequest(r, "id")
if err != nil {
return nil, err
}
return deleteInviteRequest{ID: id}, nil
}
func decodeVerifyInviteRequest(ctx context.Context, r *http.Request) (interface{}, error) {
vars := mux.Vars(r)
token, ok := vars["token"]
if !ok {
return 0, errBadRoute
}
return verifyInviteRequest{Token: token}, nil
}
func decodeListInvitesRequest(ctx context.Context, r *http.Request) (interface{}, error) {
opt, err := listOptionsFromRequest(r)
if err != nil {
return nil, err
}
return listInvitesRequest{ListOptions: opt}, nil
}