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

Function Server

services/collaboration/pkg/command/server.go:31–169  ·  view source on GitHub ↗

Server is the entrypoint for the server command.

(cfg *config.Config)

Source from the content-addressed store, hash-verified

29
30// Server is the entrypoint for the server command.
31func Server(cfg *config.Config) *cobra.Command {
32 return &cobra.Command{
33 Use: "server",
34 Short: fmt.Sprintf("start the %s service without runtime (unsupervised mode)", cfg.Service.Name),
35 PreRunE: func(cmd *cobra.Command, args []string) error {
36 return configlog.ReturnFatal(parser.ParseConfig(cfg))
37 },
38 RunE: func(cmd *cobra.Command, args []string) error {
39 logger := log.Configure(cfg.Service.Name, cfg.Commons, cfg.LogLevel)
40 traceProvider, err := tracing.GetTraceProvider(cmd.Context(), cfg.Commons.TracesExporter, cfg.Service.Name)
41 if err != nil {
42 return err
43 }
44
45 var cancel context.CancelFunc
46 if cfg.Context == nil {
47 cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...)
48 defer cancel()
49 }
50 ctx := cfg.Context
51
52 // prepare components
53 if err := helpers.RegisterOpenCloudService(ctx, cfg, logger); err != nil {
54 return err
55 }
56
57 tm, err := pool.StringToTLSMode(cfg.CS3Api.GRPCClientTLS.Mode)
58 if err != nil {
59 return err
60 }
61 gatewaySelector, err := pool.GatewaySelector(
62 cfg.CS3Api.Gateway.Name,
63 pool.WithTLSCACert(cfg.CS3Api.GRPCClientTLS.CACert),
64 pool.WithTLSMode(tm),
65 pool.WithRegistry(registry.GetRegistry()),
66 pool.WithTracerProvider(traceProvider),
67 )
68 if err != nil {
69 return err
70 }
71
72 // use the AppURLs helper (an atomic pointer) to fetch and store the app URLs
73 // this is required as the app URLs are fetched periodically in the background
74 // and read when handling requests
75 appURLs := helpers.NewAppURLs()
76
77 ticker := time.NewTicker(cfg.CS3Api.APPRegistrationInterval)
78 defer ticker.Stop()
79 go func() {
80 for ; true; <-ticker.C {
81 // fetch and store the app URLs
82 v, err := helpers.GetAppURLs(cfg, logger)
83 if err != nil {
84 logger.Warn().Err(err).Msg("Failed to get app URLs")
85 // empty map to clear previous URLs
86 v = make(map[string]map[string]string)
87 }
88 appURLs.Store(v)

Callers 1

GetCommandsFunction · 0.70

Calls 15

StoreMethod · 0.95
ReturnFatalFunction · 0.92
ParseConfigFunction · 0.92
ConfigureFunction · 0.92
GetTraceProviderFunction · 0.92
RegisterOpenCloudServiceFunction · 0.92
GetRegistryFunction · 0.92
NewAppURLsFunction · 0.92
GetAppURLsFunction · 0.92
RegisterAppProviderFunction · 0.92
NewGroupFunction · 0.92
ServerFunction · 0.92

Tested by

no test coverage detected