-
Notifications
You must be signed in to change notification settings - Fork 14
/
servicehandler.go
59 lines (48 loc) · 1.83 KB
/
servicehandler.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
47
48
49
50
51
52
53
54
55
56
57
58
59
// Code generated by sysl DO NOT EDIT.
package downstream
import (
"net/http"
"github.com/anz-bank/sysl-go/common"
"github.com/anz-bank/sysl-go/core"
"github.com/anz-bank/sysl-go/restlib"
"github.com/anz-bank/sysl-go/validator"
)
// Handler interface for Downstream
type Handler interface {
GetServiceDocsListHandler(w http.ResponseWriter, r *http.Request)
}
// ServiceHandler for Downstream API
type ServiceHandler struct {
genCallback core.RestGenCallback
serviceInterface *ServiceInterface
}
// NewServiceHandler for Downstream
func NewServiceHandler(genCallback core.RestGenCallback, serviceInterface *ServiceInterface) *ServiceHandler {
return &ServiceHandler{genCallback, serviceInterface}
}
// GetServiceDocsListHandler ...
func (s *ServiceHandler) GetServiceDocsListHandler(w http.ResponseWriter, r *http.Request) {
if s.serviceInterface.GetServiceDocsList == nil {
common.HandleError(r.Context(), w, common.InternalError, "not implemented", nil, s.genCallback.MapError)
return
}
ctx := common.RequestHeaderToContext(r.Context(), r.Header)
ctx = common.RespHeaderAndStatusToContext(ctx, make(http.Header), http.StatusOK)
var req GetServiceDocsListRequest
ctx, cancel := s.genCallback.DownstreamTimeoutContext(ctx)
defer cancel()
valErr := validator.Validate(&req)
if valErr != nil {
common.HandleError(ctx, w, common.BadRequestError, "Invalid request", valErr, s.genCallback.MapError)
return
}
client := GetServiceDocsListClient{}
servicedoc, err := s.serviceInterface.GetServiceDocsList(ctx, &req, client)
if err != nil {
common.HandleError(ctx, w, common.DownstreamUnexpectedResponseError, "Downstream failure", err, s.genCallback.MapError)
return
}
headermap, httpstatus := common.RespHeaderAndStatusFromContext(ctx)
restlib.SetHeaders(w, headermap)
restlib.SendHTTPResponse(w, httpstatus, servicedoc)
}