Revive http service for serving assets. Streamlined flagset.

This commit is contained in:
Benedikt Kulmann
2020-04-21 22:43:22 +02:00
parent 4b612965d9
commit 2f42fcb35a
9 changed files with 148 additions and 194 deletions
+14 -12
View File
@@ -3,6 +3,8 @@ package grpc
import (
"context"
"github.com/micro/cli/v2"
"github.com/owncloud/ocis-settings/pkg/metrics"
"github.com/owncloud/ocis-settings/pkg/config"
"github.com/owncloud/ocis-pkg/v2/log"
)
@@ -13,11 +15,11 @@ 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
Namespace string
Metrics *metrics.Metrics
Flags []cli.Flag
}
// newOptions initializes the available default options.
@@ -45,13 +47,6 @@ func Name(val string) Option {
}
}
// 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) {
@@ -66,9 +61,16 @@ func Config(val *config.Config) Option {
}
}
// Namespace provides a function to set the namespace option.
func Namespace(val string) Option {
// Metrics provides a function to set the metrics option.
func Metrics(val *metrics.Metrics) Option {
return func(o *Options) {
o.Namespace = val
o.Metrics = val
}
}
// Flags provides a function to set the flags option.
func Flags(val []cli.Flag) Option {
return func(o *Options) {
o.Flags = append(o.Flags, val...)
}
}
+9 -6
View File
@@ -4,6 +4,7 @@ import (
"github.com/owncloud/ocis-settings/pkg/proto/v0"
svc "github.com/owncloud/ocis-settings/pkg/service/v0"
"github.com/owncloud/ocis-pkg/v2/service/grpc"
"github.com/owncloud/ocis-settings/pkg/version"
)
// NewService initializes a new go-micro service ready to run
@@ -11,15 +12,17 @@ func Server(opts ...Option) grpc.Service {
options := newOptions(opts...)
service := grpc.NewService(
grpc.Name(options.Name),
grpc.Context(options.Context),
grpc.Address(options.Address),
grpc.Namespace(options.Namespace),
grpc.Logger(options.Logger),
grpc.Name(options.Name),
grpc.Version(version.String),
grpc.Address(options.Config.GRPC.Addr),
grpc.Namespace(options.Config.GRPC.Namespace),
grpc.Context(options.Context),
grpc.Flags(options.Flags...),
)
hdlr := svc.NewService(options.Config)
if err := proto.RegisterBundleServiceHandler(service.Server(), hdlr); err != nil {
handle := svc.NewService(options.Config)
if err := proto.RegisterBundleServiceHandler(service.Server(), handle); err != nil {
options.Logger.Fatal().Err(err).Msg("could not register service handler")
}