mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-04-23 12:38:21 -05:00
settings: Instanciate only a single instance of the ServiceHandler/Store
Share the same instance between the HTTP and the GRPC service. This is in preparation for moving the cache of the metadata storage backend to a go-micro/store based implementation. By sharing the same service instance in the HTTP and GRPC services we can avoid the usage of global variables for the caches, which will make the move to the go-micro/store implementation simpler.
This commit is contained in:
committed by
Ralf Haferkamp
parent
3e92e409f7
commit
18bb3dbaca
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
||||
"github.com/owncloud/ocis/v2/services/settings/pkg/config"
|
||||
"github.com/owncloud/ocis/v2/services/settings/pkg/metrics"
|
||||
svc "github.com/owncloud/ocis/v2/services/settings/pkg/service/v0"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
@@ -14,12 +15,13 @@ type Option func(o *Options)
|
||||
|
||||
// Options defines the available options for this package.
|
||||
type Options struct {
|
||||
Name string
|
||||
Logger log.Logger
|
||||
Context context.Context
|
||||
Config *config.Config
|
||||
Metrics *metrics.Metrics
|
||||
Flags []cli.Flag
|
||||
Name string
|
||||
Logger log.Logger
|
||||
Context context.Context
|
||||
Config *config.Config
|
||||
Metrics *metrics.Metrics
|
||||
ServiceHandler svc.Service
|
||||
Flags []cli.Flag
|
||||
}
|
||||
|
||||
// newOptions initializes the available default options.
|
||||
@@ -74,3 +76,10 @@ func Flags(val []cli.Flag) Option {
|
||||
o.Flags = append(o.Flags, val...)
|
||||
}
|
||||
}
|
||||
|
||||
// ServiceHandler provides a function to set the ServiceHandler option
|
||||
func ServiceHandler(val svc.Service) Option {
|
||||
return func(o *Options) {
|
||||
o.ServiceHandler = val
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ func Server(opts ...Option) (ohttp.Service, error) {
|
||||
return ohttp.Service{}, fmt.Errorf("could not initialize http service: %w", err)
|
||||
}
|
||||
|
||||
handle := svc.NewService(options.Config, options.Logger)
|
||||
handle := options.ServiceHandler
|
||||
|
||||
{
|
||||
handle = svc.NewInstrument(handle, options.Metrics)
|
||||
|
||||
Reference in New Issue
Block a user