Server is the entrypoint for the server command.
(cfg *config.Config)
| 33 | |
| 34 | // Server is the entrypoint for the server command. |
| 35 | func Server(cfg *config.Config) *cobra.Command { |
| 36 | return &cobra.Command{ |
| 37 | Use: "server", |
| 38 | Short: fmt.Sprintf("start the %s service without runtime (unsupervised mode)", cfg.Service.Name), |
| 39 | PreRunE: func(cmd *cobra.Command, args []string) error { |
| 40 | err := configlog.ReturnFatal(parser.ParseConfig(cfg)) |
| 41 | if err != nil { |
| 42 | return err |
| 43 | } |
| 44 | |
| 45 | if cfg.IDP.EncryptionSecretFile != "" { |
| 46 | if err := ensureEncryptionSecretExists(cfg.IDP.EncryptionSecretFile); err != nil { |
| 47 | return err |
| 48 | } |
| 49 | if err := ensureSigningPrivateKeyExists(cfg.IDP.SigningPrivateKeyFiles); err != nil { |
| 50 | return err |
| 51 | } |
| 52 | } |
| 53 | return nil |
| 54 | }, |
| 55 | RunE: func(cmd *cobra.Command, args []string) error { |
| 56 | logger := log.Configure(cfg.Service.Name, cfg.Commons, cfg.LogLevel) |
| 57 | traceProvider, err := tracing.GetTraceProvider(cmd.Context(), cfg.Commons.TracesExporter, cfg.Service.Name) |
| 58 | if err != nil { |
| 59 | return err |
| 60 | } |
| 61 | |
| 62 | var cancel context.CancelFunc |
| 63 | if cfg.Context == nil { |
| 64 | cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) |
| 65 | defer cancel() |
| 66 | } |
| 67 | ctx := cfg.Context |
| 68 | |
| 69 | metrics := metrics.New() |
| 70 | metrics.BuildInfo.WithLabelValues(version.GetString()).Set(1) |
| 71 | |
| 72 | gr := runner.NewGroup() |
| 73 | { |
| 74 | server, err := http.Server( |
| 75 | http.Logger(logger), |
| 76 | http.Context(ctx), |
| 77 | http.Config(cfg), |
| 78 | http.Metrics(metrics), |
| 79 | http.TraceProvider(traceProvider), |
| 80 | ) |
| 81 | if err != nil { |
| 82 | logger.Info(). |
| 83 | Err(err). |
| 84 | Str("transport", "http"). |
| 85 | Msg("Failed to initialize server") |
| 86 | |
| 87 | return err |
| 88 | } |
| 89 | |
| 90 | gr.Add(runner.NewGoMicroHttpServerRunner(cfg.Service.Name+".http", server)) |
| 91 | } |
| 92 |
no test coverage detected