feat(http): construct flux handler by FluxBackend

pull/11700/head
zhulongcheng 2019-01-17 00:12:57 +08:00 committed by Leo Di Donato
parent c283b068ed
commit 57dc6664f5
2 changed files with 26 additions and 6 deletions

View File

@ -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))

View File

@ -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)