generated from xmidt-org/.go-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
handler.go
51 lines (44 loc) · 1.42 KB
/
handler.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
// SPDX-FileCopyrightText: 2022 Comcast Cable Communications Management, LLC
// SPDX-License-Identifier: Apache-2.0
package ancla
import (
"context"
"net/http"
"time"
kithttp "github.com/go-kit/kit/transport/http"
"go.uber.org/zap"
)
// NewAddWebhookHandler returns an HTTP handler for adding
// a webhook registration.
func NewAddWebhookHandler(s Service, config HandlerConfig) http.Handler {
return kithttp.NewServer(
newAddWebhookEndpoint(s),
addWebhookRequestDecoder(newTransportConfig(config)),
encodeAddWebhookResponse,
kithttp.ServerErrorEncoder(errorEncoder(config.GetLogger)),
)
}
// NewGetAllWebhooksHandler returns an HTTP handler for fetching
// all the currently registered webhooks.
func NewGetAllWebhooksHandler(s Service, config HandlerConfig) http.Handler {
return kithttp.NewServer(
newGetAllWebhooksEndpoint(s),
kithttp.NopRequestDecoder,
encodeGetAllWebhooksResponse,
kithttp.ServerErrorEncoder(errorEncoder(config.GetLogger)),
)
}
// HandlerConfig contains configuration for all components that handlers depend on
// from the service to the transport layers.
type HandlerConfig struct {
V Validator
DisablePartnerIDs bool
GetLogger func(context.Context) *zap.Logger
}
func newTransportConfig(hConfig HandlerConfig) transportConfig {
return transportConfig{
now: time.Now,
v: hConfig.V,
disablePartnerIDs: hConfig.DisablePartnerIDs,
}
}