2016-09-26 18:48:55 +00:00
|
|
|
package service
|
2016-09-04 05:13:42 +00:00
|
|
|
|
|
|
|
import (
|
2017-03-15 15:55:30 +00:00
|
|
|
"context"
|
2018-05-04 01:01:57 +00:00
|
|
|
"encoding/json"
|
2016-09-04 05:13:42 +00:00
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
2018-06-15 14:13:11 +00:00
|
|
|
func decodeCreatePackRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
|
|
var req createPackRequest
|
|
|
|
if err := json.NewDecoder(r.Body).Decode(&req.payload); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return req, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func decodeModifyPackRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
|
|
id, err := idFromRequest(r, "id")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var req modifyPackRequest
|
|
|
|
if err := json.NewDecoder(r.Body).Decode(&req.payload); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
req.ID = id
|
|
|
|
return req, nil
|
|
|
|
}
|
|
|
|
|
2016-09-04 05:13:42 +00:00
|
|
|
func decodeDeletePackRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
2018-05-04 18:05:55 +00:00
|
|
|
name, err := nameFromRequest(r, "name")
|
2016-09-04 05:13:42 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var req deletePackRequest
|
2018-05-04 18:05:55 +00:00
|
|
|
req.Name = name
|
2016-09-04 05:13:42 +00:00
|
|
|
return req, nil
|
|
|
|
}
|
|
|
|
|
2018-06-15 14:13:11 +00:00
|
|
|
func decodeDeletePackByIDRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
|
|
id, err := idFromRequest(r, "id")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var req deletePackByIDRequest
|
|
|
|
req.ID = id
|
|
|
|
return req, nil
|
|
|
|
}
|
|
|
|
|
2016-09-04 05:13:42 +00:00
|
|
|
func decodeGetPackRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
|
|
id, err := idFromRequest(r, "id")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var req getPackRequest
|
|
|
|
req.ID = id
|
|
|
|
return req, nil
|
|
|
|
}
|
|
|
|
|
2016-10-13 18:21:47 +00:00
|
|
|
func decodeListPacksRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
|
|
opt, err := listOptionsFromRequest(r)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return listPacksRequest{ListOptions: opt}, nil
|
|
|
|
}
|
2018-05-04 01:01:57 +00:00
|
|
|
|
|
|
|
func decodeApplyPackSpecsRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
|
|
var req applyPackSpecsRequest
|
|
|
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return req, nil
|
|
|
|
|
|
|
|
}
|