mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-06 12:19:37 -06:00
@@ -3,8 +3,10 @@ package http
|
||||
import (
|
||||
"context"
|
||||
|
||||
gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
|
||||
"github.com/cs3org/reva/v2/pkg/events"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
||||
ehsvc "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/eventhistory/v0"
|
||||
"github.com/owncloud/ocis/v2/services/userlog/pkg/config"
|
||||
"github.com/owncloud/ocis/v2/services/userlog/pkg/metrics"
|
||||
"github.com/urfave/cli/v2"
|
||||
@@ -24,6 +26,8 @@ type Options struct {
|
||||
Namespace string
|
||||
Store store.Store
|
||||
Consumer events.Consumer
|
||||
GatewayClient gateway.GatewayAPIClient
|
||||
HistoryClient ehsvc.EventHistoryService
|
||||
RegisteredEvents []events.Unmarshaller
|
||||
}
|
||||
|
||||
@@ -94,6 +98,20 @@ func Consumer(consumer events.Consumer) Option {
|
||||
}
|
||||
}
|
||||
|
||||
// Gateway provides a function to configure the gateway client
|
||||
func Gateway(gw gateway.GatewayAPIClient) Option {
|
||||
return func(o *Options) {
|
||||
o.GatewayClient = gw
|
||||
}
|
||||
}
|
||||
|
||||
// History provides a function to configure the event history client
|
||||
func History(h ehsvc.EventHistoryService) Option {
|
||||
return func(o *Options) {
|
||||
o.HistoryClient = h
|
||||
}
|
||||
}
|
||||
|
||||
// RegisteredEvents provides a function to register events
|
||||
func RegisteredEvents(evs []events.Unmarshaller) Option {
|
||||
return func(o *Options) {
|
||||
|
||||
@@ -3,6 +3,11 @@ package http
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
stdhttp "net/http"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
chimiddleware "github.com/go-chi/chi/v5/middleware"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/middleware"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/service/http"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/version"
|
||||
svc "github.com/owncloud/ocis/v2/services/userlog/pkg/service"
|
||||
@@ -34,27 +39,34 @@ func Server(opts ...Option) (http.Service, error) {
|
||||
return http.Service{}, fmt.Errorf("could not initialize http service: %w", err)
|
||||
}
|
||||
|
||||
//middlewares := []func(stdhttp.Handler) stdhttp.Handler{
|
||||
//middleware.TraceContext,
|
||||
//chimiddleware.RequestID,
|
||||
//middleware.Version(
|
||||
//"userlog",
|
||||
//version.GetString(),
|
||||
//),
|
||||
//middleware.Logger(
|
||||
//options.Logger,
|
||||
//),
|
||||
//}
|
||||
|
||||
handle, err := svc.NewUserlogService(options.Config, options.Consumer, options.Store, options.RegisteredEvents)
|
||||
if err != nil {
|
||||
return http.Service{}, err
|
||||
middlewares := []func(stdhttp.Handler) stdhttp.Handler{
|
||||
middleware.TraceContext,
|
||||
chimiddleware.RequestID,
|
||||
middleware.Version(
|
||||
"userlog",
|
||||
version.GetString(),
|
||||
),
|
||||
middleware.Logger(
|
||||
options.Logger,
|
||||
),
|
||||
middleware.ExtractAccountUUID(),
|
||||
}
|
||||
|
||||
{
|
||||
//handle = svc.NewInstrument(handle, options.Metrics)
|
||||
//handle = svc.NewLogging(handle, options.Logger)
|
||||
//handle = svc.NewTracing(handle)
|
||||
mux := chi.NewMux()
|
||||
mux.Use(middlewares...)
|
||||
|
||||
handle, err := svc.NewUserlogService(
|
||||
svc.Logger(options.Logger),
|
||||
svc.Consumer(options.Consumer),
|
||||
svc.Mux(mux),
|
||||
svc.Store(options.Store),
|
||||
svc.Config(options.Config),
|
||||
svc.HistoryClient(options.HistoryClient),
|
||||
svc.GatewayClient(options.GatewayClient),
|
||||
svc.RegisteredEvents(options.RegisteredEvents),
|
||||
)
|
||||
if err != nil {
|
||||
return http.Service{}, err
|
||||
}
|
||||
|
||||
if err := micro.RegisterHandler(service.Server(), handle); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user