MCPcopy
hub / github.com/opencloud-eu/opencloud / Server

Function Server

services/search/pkg/command/server.go:39–240  ·  view source on GitHub ↗

Server is the entrypoint for the server command.

(cfg *config.Config)

Source from the content-addressed store, hash-verified

37
38// Server is the entrypoint for the server command.
39func Server(cfg *config.Config) *cobra.Command {
40 return &cobra.Command{
41 Use: "server",
42 Short: fmt.Sprintf("start the %s service without runtime (unsupervised mode)", cfg.Service.Name),
43 PreRunE: func(cmd *cobra.Command, args []string) error {
44 return configlog.ReturnFatal(parser.ParseConfig(cfg))
45 },
46 RunE: func(cmd *cobra.Command, args []string) error {
47 logger := log.Configure(cfg.Service.Name, cfg.Commons, cfg.LogLevel)
48 traceProvider, err := tracing.GetTraceProvider(cmd.Context(), cfg.Commons.TracesExporter, cfg.Service.Name)
49 if err != nil {
50 return err
51 }
52
53 cfg.GrpcClient, err = ogrpc.NewClient(
54 append(ogrpc.GetClientOptions(cfg.GRPCClientTLS), ogrpc.WithTraceProvider(traceProvider))...,
55 )
56 if err != nil {
57 return err
58 }
59
60 var cancel context.CancelFunc
61 if cfg.Context == nil {
62 cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...)
63 defer cancel()
64 }
65 ctx := cfg.Context
66
67 mtrcs := metrics.New()
68 mtrcs.BuildInfo.WithLabelValues(version.GetString()).Set(1)
69
70 // initialize search engine
71 var eng search.Engine
72 switch cfg.Engine.Type {
73 case "bleve":
74 idx, err := bleve.NewIndex(cfg.Engine.Bleve.Datapath)
75 if err != nil {
76 return err
77 }
78
79 defer func() {
80 if err = idx.Close(); err != nil {
81 logger.Error().Err(err).Msg("could not close bleve index")
82 }
83 }()
84
85 eng = bleve.NewBackend(idx, bleveQuery.DefaultCreator, logger)
86 case "open-search":
87 clientConfig := opensearchgo.Config{
88 Addresses: cfg.Engine.OpenSearch.Client.Addresses,
89 Username: cfg.Engine.OpenSearch.Client.Username,
90 Password: cfg.Engine.OpenSearch.Client.Password,
91 Header: cfg.Engine.OpenSearch.Client.Header,
92 RetryOnStatus: cfg.Engine.OpenSearch.Client.RetryOnStatus,
93 DisableRetry: cfg.Engine.OpenSearch.Client.DisableRetry,
94 EnableRetryOnTimeout: cfg.Engine.OpenSearch.Client.EnableRetryOnTimeout,
95 MaxRetries: cfg.Engine.OpenSearch.Client.MaxRetries,
96 CompressRequestBody: cfg.Engine.OpenSearch.Client.CompressRequestBody,

Callers 1

GetCommandsFunction · 0.70

Calls 15

ReturnFatalFunction · 0.92
ParseConfigFunction · 0.92
ConfigureFunction · 0.92
GetTraceProviderFunction · 0.92
NewFunction · 0.92
GetStringFunction · 0.92
NewBackendFunction · 0.92
GetRegistryFunction · 0.92
NewBasicExtractorFunction · 0.92
NewTikaExtractorFunction · 0.92
NewServiceFunction · 0.92
NewGroupFunction · 0.92

Tested by

no test coverage detected