-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.go
68 lines (57 loc) · 1.9 KB
/
service.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
package btpprovisioning
import (
"context"
"github.com/nnicora/sap-sdk-go/internal/processors"
"github.com/nnicora/sap-sdk-go/sap"
"github.com/nnicora/sap-sdk-go/sap/endpoints"
"github.com/nnicora/sap-sdk-go/sap/http/request"
"github.com/nnicora/sap-sdk-go/sap/http/request/processors/jsonbuiltin"
"github.com/nnicora/sap-sdk-go/sap/metainfo"
"github.com/nnicora/sap-sdk-go/sap/service"
)
type ProvisioningV1 struct {
*service.Requester
}
const (
ServiceName = "Provisioning Service V1" // Label of service.
EndpointsID = "provisioning" // ID to lookup a service endpoint with.
ServiceID = "provisioning" // ServiceID is a unique identifier of a specific service.
)
func New(p service.RequesterConfig) *ProvisioningV1 {
c, err := p.ServiceConfig(EndpointsID)
if err != nil {
c.Processors.Using(request.Validate).PushFrontHandler(func(t interface{}) {
r := t.(*request.Request)
r.Error = err
})
}
return newRequester(c.RuntimeConfig, c.Processors, c.Endpoint)
}
func newRequester(cfg *sap.RuntimeConfig, p *processors.Processors, endpoint *endpoints.Endpoint) *ProvisioningV1 {
svc := &ProvisioningV1{
Requester: service.NewRequester(
cfg,
metainfo.ServiceInfo{
ServiceName: ServiceName,
ServiceID: ServiceID,
Endpoint: endpoint,
APIVersion: "v1",
},
p,
),
}
// Processors
p.Using(request.Build).
PushBack(&jsonbuiltin.BuildProcessor).
PushBack(&jsonbuiltin.MarshalToRequestJSONBodyProcessor)
p.Using(request.Unmarshal).
PushBack(&jsonbuiltin.UnmarshalResponseJSONBodyProcessor)
p.Using(request.UnmarshalError).
PushBack(&jsonbuiltin.UnmarshalErrorResponseJSONBodyProcessor)
p.Using(request.UnmarshalMeta).
PushBack(&jsonbuiltin.UnmarshalMetaProcessor)
return svc
}
func (svc *ProvisioningV1) newRequest(ctx context.Context, op *request.Operation, in, out interface{}) *request.Request {
return svc.NewRequest(ctx, op, in, out)
}