commands

package
v1.1.2003 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RootCmd = &cobra.Command{
	Use:   "shar",
	Short: "SHAR Server",
	Long:  ``,

	Run: func(cmd *cobra.Command, args []string) {
		ctx := context.WithValue(context.Background(), ctxkey.Service, "shar-server")
		if err := global_telemetry.Setup(ctx, "shar-server"); err != nil {
			panic(fmt.Errorf("setup telemetry: %w", err))
		}
		log := global_telemetry.DefaultLogger(ctx, true)

		cfg, err := config.GetEnvironment()
		if err != nil {

			log.Log(ctx, errors.FatalLevel, err.Error())
		}
		nc, err := server.ConnectNats(cfg.JetStreamDomain, cfg.NatsURL, []nats.Option{nats.MaxReconnects(cfg.NatsMaxReconnects)}, false)
		if err != nil {
			panic(fmt.Errorf("connect nats: %w", err))
		}

		options := []option.Option{option.Concurrency(cfg.Concurrency), option.NatsUrl(cfg.NatsURL), option.GrpcPort(cfg.Port)}

		if cfg.JetStreamDomain != "" {
			options = append(options, option.WithJetStreamDomain(cfg.JetStreamDomain))
		}

		switch cfg.HistoryStore {
		case "nats":
			options = append(options, option.WithHistoryStore(option.NatsKV, ""))
		case "postgres":
			options = append(options, option.WithHistoryStore(option.Postgres, cfg.HistoryStoreConnection))
		}

		var svr *server.Server
		if svr, err = server.New(nc, options...); err != nil {
			panic(fmt.Errorf("creating server: %w", err))
		}

		if err = svr.Listen(); err != nil {
			panic(fmt.Errorf("starting server: %w", err))
		}
	},
	PersistentPreRun: func(cmd *cobra.Command, args []string) {

	},
}

RootCmd represents the base command when called without any subcommands

Functions

func Execute

func Execute()

Execute adds all child commands to the root command and sets flag appropriately. This is called by main.main(). It only needs to happen once to the RootCmd.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL