-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhandler.go
More file actions
52 lines (45 loc) · 1.55 KB
/
handler.go
File metadata and controls
52 lines (45 loc) · 1.55 KB
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
// 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"
webhook "github.com/xmidt-org/webhook-schema"
"go.uber.org/zap"
)
// NewAddWRPEventStreamHandler returns an HTTP handler for adding
// a wrpEventStream registration.
func NewAddWRPEventStreamHandler(s Service, config HandlerConfig) http.Handler {
return kithttp.NewServer(
newAddWRPEventStreamEndpoint(s),
addWRPEventStreamRequestDecoder(newTransportConfig(config)),
encodeAddWRPEventStreamResponse,
kithttp.ServerErrorEncoder(errorEncoder(config.GetLogger)),
)
}
// NewGetAllWRPEventStreamsHandler returns an HTTP handler for fetching
// all the currently registered wrpEventStreams.
func NewGetAllWRPEventStreamsHandler(s Service, config HandlerConfig) http.Handler {
return kithttp.NewServer(
newGetAllWRPEventStreamsEndpoint(s),
kithttp.NopRequestDecoder,
encodeGetAllWRPEventStreamsResponse,
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 webhook.Validators
DisablePartnerIDs bool
GetLogger func(context.Context) *zap.Logger
}
func newTransportConfig(hConfig HandlerConfig) transportConfig {
return transportConfig{
now: time.Now,
v: hConfig.V,
disablePartnerIDs: hConfig.DisablePartnerIDs,
}
}