-
Notifications
You must be signed in to change notification settings - Fork 14
/
servicehandler.go
98 lines (81 loc) · 3.1 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Code generated by sysl DO NOT EDIT.
package deps
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 Deps
type Handler interface {
GetApiDocsListHandler(w http.ResponseWriter, r *http.Request)
GetSuccessListHandler(w http.ResponseWriter, r *http.Request)
}
// ServiceHandler for Deps API
type ServiceHandler struct {
genCallback core.RestGenCallback
serviceInterface *ServiceInterface
}
// NewServiceHandler for Deps
func NewServiceHandler(genCallback core.RestGenCallback, serviceInterface *ServiceInterface) *ServiceHandler {
return &ServiceHandler{genCallback, serviceInterface}
}
// GetApiDocsListHandler ...
func (s *ServiceHandler) GetApiDocsListHandler(w http.ResponseWriter, r *http.Request) {
if s.serviceInterface.GetApiDocsList == 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 GetApiDocsListRequest
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 := GetApiDocsListClient{}
apidoc, err := s.serviceInterface.GetApiDocsList(ctx, &req, client)
if err != nil {
common.HandleError(ctx, w, common.DownstreamUnexpectedResponseError, "Downstream failure", err, s.genCallback.MapError)
return
}
headermap, httpstatus := common.RespHeaderAndStatusFromContext(ctx)
if headermap.Get("Content-Type") == "" {
headermap.Set("Content-Type", "application/json")
}
restlib.SetHeaders(w, headermap)
restlib.SendHTTPResponse(w, httpstatus, apidoc)
}
// GetSuccessListHandler ...
func (s *ServiceHandler) GetSuccessListHandler(w http.ResponseWriter, r *http.Request) {
if s.serviceInterface.GetSuccessList == 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 GetSuccessListRequest
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 := GetSuccessListClient{}
err := s.serviceInterface.GetSuccessList(ctx, &req, client)
if err != nil {
common.HandleError(ctx, w, common.DownstreamUnexpectedResponseError, "Downstream failure", err, s.genCallback.MapError)
return
}
headermap, httpstatus := common.RespHeaderAndStatusFromContext(ctx)
if headermap.Get("Content-Type") == "" {
headermap.Set("Content-Type", "application/json")
}
restlib.SetHeaders(w, headermap)
restlib.SendHTTPResponse(w, httpstatus, nil)
}