Separate out grpc client to package local for thumbnails service.

This commit is contained in:
Daniel Swärd
2023-07-27 12:22:28 +02:00
parent 94aab8b38d
commit d21b03b14c
4 changed files with 12 additions and 3 deletions

View File

@@ -12,6 +12,7 @@ import (
ociscrypto "github.com/owncloud/ocis/v2/ocis-pkg/crypto"
"github.com/owncloud/ocis/v2/ocis-pkg/registry"
"go-micro.dev/v4"
"go-micro.dev/v4/client"
"go-micro.dev/v4/server"
)
@@ -22,6 +23,11 @@ type Service struct {
// NewService initializes a new grpc service.
func NewService(opts ...Option) (Service, error) {
return NewServiceWithClient(DefaultClient(), opts...)
}
// NewServiceWithClient initializes a new grpc service with explicit client.
func NewServiceWithClient(client client.Client, opts ...Option) (Service, error) {
var mServer server.Server
sopts := newOptions(opts...)
tlsConfig := &tls.Config{}
@@ -52,7 +58,7 @@ func NewService(opts ...Option) (Service, error) {
// first add a server because it will reset any options
micro.Server(mServer),
// also add a client that can be used after initializing the service
micro.Client(DefaultClient()),
micro.Client(client),
micro.Address(sopts.Address),
micro.Name(strings.Join([]string{sopts.Namespace, sopts.Name}, ".")),
micro.Version(sopts.Version),

View File

@@ -34,7 +34,7 @@ func Server(cfg *config.Config) *cli.Command {
if err != nil {
return err
}
err = ogrpc.Configure(ogrpc.GetClientOptions(cfg.GRPCClientTLS)...)
cfg.GrpcClient, err = ogrpc.NewClient(ogrpc.GetClientOptions(cfg.GRPCClientTLS)...)
if err != nil {
return err
}

View File

@@ -5,6 +5,7 @@ import (
"context"
"github.com/owncloud/ocis/v2/ocis-pkg/shared"
"go-micro.dev/v4/client"
)
// Config combines all available configuration parts.
@@ -21,6 +22,7 @@ type Config struct {
HTTP HTTP `yaml:"http"`
GRPCClientTLS *shared.GRPCClientTLS `yaml:"grpc_client_tls"`
GrpcClient client.Client `yaml:"-"`
Thumbnail Thumbnail `yaml:"thumbnail"`

View File

@@ -16,7 +16,8 @@ import (
func NewService(opts ...Option) grpc.Service {
options := newOptions(opts...)
service, err := grpc.NewService(
service, err := grpc.NewServiceWithClient(
options.Config.GrpcClient,
grpc.TLSEnabled(options.Config.GRPC.TLS.Enabled),
grpc.TLSCert(
options.Config.GRPC.TLS.Cert,