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) { cfg, err := config.GetEnvironment() if err != nil { log.Fatal(err) } var lev slog.Level var addSource bool switch cfg.LogLevel { case "debug": lev = slog.LevelDebug addSource = true case "info": lev = slog.LevelInfo case "warn": lev = slog.LevelWarn case "trace": lev = errors.TraceLevel case "verbose": lev = errors.VerboseLevel default: lev = slog.LevelError } 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)) } handlerFactoryFns := map[string]func() slog.Handler{ "text": func() slog.Handler { return common.NewTextHandler(lev, addSource) }, "shar-handler": func() slog.Handler { return common.NewSharHandler(common.HandlerOptions{Level: lev}, &common.NatsLogPublisher{Conn: nc.Conn}) }, } cfgHandlers := strings.Split(cfg.LogHandler, ",") handlers := make([]slog.Handler, 0, len(cfgHandlers)) for _, h := range cfgHandlers { handlers = append(handlers, handlerFactoryFns[h]()) } logx.SetDefault("shar", common.NewMultiHandler(handlers)) 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)) } 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 ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.