Files
ocis/services/postprocessing/pkg/command/server.go
T

48 lines
1.3 KiB
Go
Raw Normal View History

2022-07-08 13:17:01 +02:00
package command
import (
"fmt"
"os"
"github.com/cs3org/reva/v2/pkg/events/server"
"github.com/go-micro/plugins/v4/events/natsjs"
"github.com/owncloud/ocis/v2/services/postprocessing/pkg/config"
"github.com/owncloud/ocis/v2/services/postprocessing/pkg/config/parser"
"github.com/owncloud/ocis/v2/services/postprocessing/pkg/logging"
"github.com/owncloud/ocis/v2/services/postprocessing/pkg/service"
"github.com/urfave/cli/v2"
)
// Server is the entrypoint for the server command.
func Server(cfg *config.Config) *cli.Command {
return &cli.Command{
Name: "server",
2022-07-20 13:40:25 +02:00
Usage: fmt.Sprintf("start %s service without runtime (unsupervised mode)", cfg.Service.Name),
2022-07-08 13:17:01 +02:00
Category: "server",
Before: func(c *cli.Context) error {
err := parser.ParseConfig(cfg)
if err != nil {
fmt.Printf("%v", err)
os.Exit(1)
}
return err
},
Action: func(c *cli.Context) error {
logger := logging.Configure(cfg.Service.Name, cfg.Log)
evtsCfg := cfg.Postprocessing.Events
client, err := server.NewNatsStream(
natsjs.Address(evtsCfg.Endpoint),
natsjs.ClusterID(evtsCfg.Cluster),
)
if err != nil {
return err
}
svc, err := service.NewPostprocessingService(client, logger, cfg.Postprocessing)
if err != nil {
return err
}
return svc.Run()
},
}
}