feat(http): construct flux handler by FluxBackend
parent
c283b068ed
commit
57dc6664f5
|
@ -127,10 +127,8 @@ func NewAPIHandler(b *APIBackend) *APIHandler {
|
|||
writeBackend := NewWriteBackend(b)
|
||||
h.WriteHandler = NewWriteHandler(writeBackend)
|
||||
|
||||
h.QueryHandler = NewFluxHandler()
|
||||
h.QueryHandler.OrganizationService = b.OrganizationService
|
||||
h.QueryHandler.Logger = b.Logger.With(zap.String("handler", "query"))
|
||||
h.QueryHandler.ProxyQueryService = b.ProxyQueryService
|
||||
fluxBackend := NewFluxBackend(b)
|
||||
h.QueryHandler = NewFluxHandler(fluxBackend)
|
||||
|
||||
h.ProtoHandler = NewProtoHandler(NewProtoBackend(b))
|
||||
|
||||
|
|
|
@ -27,6 +27,25 @@ const (
|
|||
fluxPath = "/api/v2/query"
|
||||
)
|
||||
|
||||
// FluxBackend is all services and associated parameters required to construct
|
||||
// the FluxHandler.
|
||||
type FluxBackend struct {
|
||||
Logger *zap.Logger
|
||||
|
||||
OrganizationService platform.OrganizationService
|
||||
ProxyQueryService query.ProxyQueryService
|
||||
}
|
||||
|
||||
// NewFluxBackend returns a new instance of FluxBackend.
|
||||
func NewFluxBackend(b *APIBackend) *FluxBackend {
|
||||
return &FluxBackend{
|
||||
Logger: b.Logger.With(zap.String("handler", "query")),
|
||||
|
||||
ProxyQueryService: b.ProxyQueryService,
|
||||
OrganizationService: b.OrganizationService,
|
||||
}
|
||||
}
|
||||
|
||||
// FluxHandler implements handling flux queries.
|
||||
type FluxHandler struct {
|
||||
*httprouter.Router
|
||||
|
@ -39,11 +58,14 @@ type FluxHandler struct {
|
|||
}
|
||||
|
||||
// NewFluxHandler returns a new handler at /api/v2/query for flux queries.
|
||||
func NewFluxHandler() *FluxHandler {
|
||||
func NewFluxHandler(b *FluxBackend) *FluxHandler {
|
||||
h := &FluxHandler{
|
||||
Router: NewRouter(),
|
||||
Now: time.Now,
|
||||
Logger: zap.NewNop(),
|
||||
Logger: b.Logger,
|
||||
|
||||
ProxyQueryService: b.ProxyQueryService,
|
||||
OrganizationService: b.OrganizationService,
|
||||
}
|
||||
|
||||
h.HandlerFunc("POST", fluxPath, h.handleQuery)
|
||||
|
|
Loading…
Reference in New Issue