MCPcopy Index your code
hub / github.com/opencloud-eu/opencloud / Server

Function Server

services/web/pkg/command/server.go:24–107  ·  view source on GitHub ↗

Server is the entrypoint for the server command.

(cfg *config.Config)

Source from the content-addressed store, hash-verified

22
23// Server is the entrypoint for the server command.
24func Server(cfg *config.Config) *cobra.Command {
25 return &cobra.Command{
26 Use: "server",
27 Short: fmt.Sprintf("start the %s service without runtime (unsupervised mode)", cfg.Service.Name),
28 PreRunE: func(cmd *cobra.Command, args []string) error {
29 return configlog.ReturnFatal(parser.ParseConfig(cfg))
30 },
31 RunE: func(cmd *cobra.Command, args []string) error {
32 logger := log.Configure(cfg.Service.Name, cfg.Commons, cfg.LogLevel)
33 traceProvider, err := tracing.GetTraceProvider(cmd.Context(), cfg.Commons.TracesExporter, cfg.Service.Name)
34 if err != nil {
35 return err
36 }
37
38 // actually read the contents of the config file and override defaults
39 if cfg.File != "" {
40 contents, err := os.ReadFile(cfg.File)
41 if err != nil {
42 logger.Err(err).Msg("error opening config file")
43 return err
44 }
45 if err = json.Unmarshal(contents, &cfg.Web.Config); err != nil {
46 logger.Fatal().Err(err).Msg("error unmarshalling config file")
47 return err
48 }
49 }
50
51 var cancel context.CancelFunc
52 if cfg.Context == nil {
53 cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...)
54 defer cancel()
55 }
56 ctx := cfg.Context
57
58 m := metrics.New()
59
60 gr := runner.NewGroup()
61 {
62 server, err := http.Server(
63 http.Logger(logger),
64 http.Context(ctx),
65 http.Namespace(cfg.HTTP.Namespace),
66 http.Config(cfg),
67 http.Metrics(m),
68 http.TraceProvider(traceProvider),
69 )
70 if err != nil {
71 logger.Info().
72 Err(err).
73 Str("transport", "http").
74 Msg("Failed to initialize server")
75
76 return err
77 }
78
79 gr.Add(runner.NewGoMicroHttpServerRunner(cfg.Service.Name+".http", server))
80 }
81

Callers 1

GetCommandsFunction · 0.70

Calls 15

ReturnFatalFunction · 0.92
ParseConfigFunction · 0.92
ConfigureFunction · 0.92
GetTraceProviderFunction · 0.92
NewFunction · 0.92
NewGroupFunction · 0.92
ServerFunction · 0.92
LoggerFunction · 0.92
ContextFunction · 0.92
NamespaceFunction · 0.92
ConfigFunction · 0.92
MetricsFunction · 0.92

Tested by

no test coverage detected