mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
package service
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"golang.org/x/net/context"
|
|
)
|
|
|
|
func decodeCreateQueryRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
var req createQueryRequest
|
|
if err := json.NewDecoder(r.Body).Decode(&req.payload); err != nil {
|
|
return nil, err
|
|
}
|
|
return req, nil
|
|
}
|
|
|
|
func decodeModifyQueryRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
id, err := idFromRequest(r, "id")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var req modifyQueryRequest
|
|
if err := json.NewDecoder(r.Body).Decode(&req.payload); err != nil {
|
|
return nil, err
|
|
}
|
|
req.ID = id
|
|
return req, nil
|
|
}
|
|
|
|
func decodeDeleteQueryRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
id, err := idFromRequest(r, "id")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var req deleteQueryRequest
|
|
req.ID = id
|
|
return req, nil
|
|
}
|
|
|
|
func decodeGetQueryRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
id, err := idFromRequest(r, "id")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var req getQueryRequest
|
|
req.ID = id
|
|
return req, nil
|
|
}
|