-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviews.go
46 lines (38 loc) · 1.02 KB
/
views.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package service
import (
"context"
"encoding/json"
"errors"
"net/http"
"strconv"
"github.com/gorilla/mux"
store "github.com/konjoot/drivers-go-kit/src/drivers/datastore"
)
type driversGetByIDRequest struct {
ID uint64 `json:"id"`
}
// DecodeDriversGetByIDRequest is a request decoder for GetByID endpoint
func DecodeDriversGetByIDRequest(_ context.Context, r *http.Request) (interface{}, error) {
vars := mux.Vars(r)
idString, ok := vars["id"]
if !ok {
return nil, errors.New("Bad routing")
}
id, err := strconv.Atoi(idString)
if err != nil {
return nil, err
}
return driversGetByIDRequest{ID: uint64(id)}, nil
}
type driversImportRequest struct {
Drivers []*store.Driver
}
// DecodeDriversImportRequest is a request decoder for Import endpoint
func DecodeDriversImportRequest(_ context.Context, r *http.Request) (interface{}, error) {
var request driversImportRequest
if err := json.NewDecoder(r.Body).Decode(&request.Drivers); err != nil {
return nil, err
}
return request, nil
}
type emptyResponse struct{}