Add 'thumbnails/' from commit '2ebf7b2f23af96b3b499c401fe5498a9349403d8'
git-subtree-dir: thumbnails git-subtree-mainline:ccc651a11egit-subtree-split:2ebf7b2f23
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
package grpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/micro/cli/v2"
|
||||
"github.com/owncloud/ocis-pkg/v2/log"
|
||||
"github.com/owncloud/ocis-thumbnails/pkg/config"
|
||||
"github.com/owncloud/ocis-thumbnails/pkg/metrics"
|
||||
)
|
||||
|
||||
// Option defines a single option function.
|
||||
type Option func(o *Options)
|
||||
|
||||
// Options defines the available options for this package.
|
||||
type Options struct {
|
||||
Name string
|
||||
Address string
|
||||
Logger log.Logger
|
||||
Context context.Context
|
||||
Config *config.Config
|
||||
Metrics *metrics.Metrics
|
||||
Namespace string
|
||||
Flags []cli.Flag
|
||||
}
|
||||
|
||||
// newOptions initializes the available default options.
|
||||
func newOptions(opts ...Option) Options {
|
||||
opt := Options{}
|
||||
|
||||
for _, o := range opts {
|
||||
o(&opt)
|
||||
}
|
||||
|
||||
return opt
|
||||
}
|
||||
|
||||
// Logger provides a function to set the logger option.
|
||||
func Logger(val log.Logger) Option {
|
||||
return func(o *Options) {
|
||||
o.Logger = val
|
||||
}
|
||||
}
|
||||
|
||||
// Name provides a name for the service.
|
||||
func Name(val string) Option {
|
||||
return func(o *Options) {
|
||||
o.Name = val
|
||||
}
|
||||
}
|
||||
|
||||
// Address provides an address for the service.
|
||||
func Address(val string) Option {
|
||||
return func(o *Options) {
|
||||
o.Address = val
|
||||
}
|
||||
}
|
||||
|
||||
// Context provides a function to set the context option.
|
||||
func Context(val context.Context) Option {
|
||||
return func(o *Options) {
|
||||
o.Context = val
|
||||
}
|
||||
}
|
||||
|
||||
// Config provides a function to set the config option.
|
||||
func Config(val *config.Config) Option {
|
||||
return func(o *Options) {
|
||||
o.Config = val
|
||||
}
|
||||
}
|
||||
|
||||
// Metrics provides a function to set the metrics option.
|
||||
func Metrics(val *metrics.Metrics) Option {
|
||||
return func(o *Options) {
|
||||
o.Metrics = val
|
||||
}
|
||||
}
|
||||
|
||||
// Namespace provides a function to set the namespace option.
|
||||
func Namespace(val string) Option {
|
||||
return func(o *Options) {
|
||||
o.Namespace = val
|
||||
}
|
||||
}
|
||||
|
||||
// Flags provides a function to set the flags option.
|
||||
func Flags(flags []cli.Flag) Option {
|
||||
return func(o *Options) {
|
||||
o.Flags = append(o.Flags, flags...)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package grpc
|
||||
|
||||
import (
|
||||
"github.com/owncloud/ocis-pkg/v2/service/grpc"
|
||||
"github.com/owncloud/ocis-thumbnails/pkg/proto/v0"
|
||||
svc "github.com/owncloud/ocis-thumbnails/pkg/service/v0"
|
||||
"github.com/owncloud/ocis-thumbnails/pkg/thumbnail/imgsource"
|
||||
"github.com/owncloud/ocis-thumbnails/pkg/thumbnail/storage"
|
||||
"github.com/owncloud/ocis-thumbnails/pkg/version"
|
||||
)
|
||||
|
||||
// NewService initializes the grpc service and server.
|
||||
func NewService(opts ...Option) grpc.Service {
|
||||
options := newOptions(opts...)
|
||||
|
||||
service := grpc.NewService(
|
||||
grpc.Logger(options.Logger),
|
||||
grpc.Namespace(options.Namespace),
|
||||
grpc.Name(options.Name),
|
||||
grpc.Version(version.String),
|
||||
grpc.Address(options.Address),
|
||||
grpc.Context(options.Context),
|
||||
grpc.Flags(options.Flags...),
|
||||
)
|
||||
|
||||
var thumbnail proto.ThumbnailServiceHandler
|
||||
{
|
||||
thumbnail = svc.NewService(
|
||||
svc.Config(options.Config),
|
||||
svc.Logger(options.Logger),
|
||||
svc.ThumbnailSource(imgsource.NewWebDavSource(options.Config.Thumbnail.WebDavSource)),
|
||||
svc.ThumbnailStorage(
|
||||
storage.NewFileSystemStorage(
|
||||
options.Config.Thumbnail.FileSystemStorage,
|
||||
options.Logger,
|
||||
),
|
||||
),
|
||||
)
|
||||
thumbnail = svc.NewInstrument(thumbnail, options.Metrics)
|
||||
thumbnail = svc.NewLogging(thumbnail, options.Logger)
|
||||
}
|
||||
|
||||
_ = proto.RegisterThumbnailServiceHandler(
|
||||
service.Server(),
|
||||
thumbnail,
|
||||
)
|
||||
|
||||
service.Init()
|
||||
return service
|
||||
}
|
||||
Reference in New Issue
Block a user