Server is the entrypoint for the server command.
(cfg *config.Config)
| 21 | |
| 22 | // Server is the entrypoint for the server command. |
| 23 | func Server(cfg *config.Config) *cobra.Command { |
| 24 | return &cobra.Command{ |
| 25 | Use: "server", |
| 26 | Short: fmt.Sprintf("start %s service without runtime (unsupervised mode)", cfg.Service.Name), |
| 27 | PreRunE: func(cmd *cobra.Command, args []string) error { |
| 28 | err := parser.ParseConfig(cfg) |
| 29 | if err != nil { |
| 30 | fmt.Printf("%v", err) |
| 31 | os.Exit(1) |
| 32 | } |
| 33 | return err |
| 34 | }, |
| 35 | RunE: func(cmd *cobra.Command, args []string) error { |
| 36 | logger := log.Configure(cfg.Service.Name, cfg.Commons, cfg.LogLevel) |
| 37 | |
| 38 | var cancel context.CancelFunc |
| 39 | if cfg.Context == nil { |
| 40 | cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) |
| 41 | defer cancel() |
| 42 | } |
| 43 | ctx := cfg.Context |
| 44 | |
| 45 | traceProvider, err := tracing.GetTraceProvider(cmd.Context(), cfg.Commons.TracesExporter, cfg.Service.Name) |
| 46 | if err != nil { |
| 47 | return err |
| 48 | } |
| 49 | |
| 50 | gr := runner.NewGroup() |
| 51 | { |
| 52 | st := store.Create( |
| 53 | store.Store(cfg.Store.Store), |
| 54 | store.TTL(cfg.Store.TTL), |
| 55 | microstore.Nodes(cfg.Store.Nodes...), |
| 56 | microstore.Database(cfg.Store.Database), |
| 57 | microstore.Table(cfg.Store.Table), |
| 58 | store.Authentication(cfg.Store.AuthUsername, cfg.Store.AuthPassword), |
| 59 | store.TLSEnabled(cfg.Store.EnableTLS), |
| 60 | store.TLSInsecure(cfg.Store.TLSInsecure), |
| 61 | store.TLSRootCA(cfg.Store.TLSRootCACertificate), |
| 62 | ) |
| 63 | |
| 64 | svc, err := service.NewPostprocessingService(ctx, logger, st, traceProvider, cfg) |
| 65 | if err != nil { |
| 66 | return err |
| 67 | } |
| 68 | |
| 69 | gr.Add(runner.New(cfg.Service.Name+".svc", func() error { |
| 70 | return svc.Run() |
| 71 | }, func() { |
| 72 | svc.Close() |
| 73 | })) |
| 74 | } |
| 75 | |
| 76 | { |
| 77 | debugServer, err := debug.Server( |
| 78 | debug.Logger(logger), |
| 79 | debug.Context(ctx), |
| 80 | debug.Config(cfg), |
no test coverage detected