Use: "broker", Short: "The Things Network broker", Long: ``, PreRun: func(cmd *cobra.Command, args []string) { ctx.WithFields(log.Fields{ "Server": fmt.Sprintf("%s:%d", viper.GetString("broker.server-address"), viper.GetInt("broker.server-port")), "Announce": fmt.Sprintf("%s:%d", viper.GetString("broker.server-address-announce"), viper.GetInt("broker.server-port")), "NetworkServer": viper.GetString("broker.networkserver-address"), "DeduplicationDelay": viper.GetString("broker.deduplication-delay"), }).Info("Initializing Broker") }, Run: func(cmd *cobra.Command, args []string) { ctx.Info("Starting") // Component component, err := component.New(ctx, "broker", fmt.Sprintf("%s:%d", viper.GetString("broker.server-address-announce"), viper.GetInt("broker.server-port"))) if err != nil { ctx.WithError(err).Fatal("Could not initialize component") } var nsCert string if nsCertFile := viper.GetString("broker.networkserver-cert"); nsCertFile != "" { contents, err := ioutil.ReadFile(nsCertFile) if err != nil { ctx.WithError(err).Fatal("Could not get Networkserver certificate") } nsCert = string(contents) } // Broker broker := broker.NewBroker(
}).Info("Initializing Discovery") }, Run: func(cmd *cobra.Command, args []string) { ctx.Info("Starting") // Redis Client client := redis.NewClient(&redis.Options{ Addr: viper.GetString("discovery.redis-address"), Password: "", // no password set DB: viper.GetInt("discovery.redis-db"), }) connectRedis(client) // Component component, err := component.New(ctx, "discovery", fmt.Sprintf("%s:%d", "localhost", viper.GetInt("discovery.server-port"))) if err != nil { ctx.WithError(err).Fatal("Could not initialize component") } // Discovery Server discovery := discovery.NewRedisDiscovery(client) if viper.GetBool("discovery.cache") { discovery.WithCache(announcement.DefaultCacheOptions) } discovery.WithMasterAuthServers(viper.GetStringSlice("discovery.master-auth-servers")...) err = discovery.Init(component) if err != nil { ctx.WithError(err).Fatal("Could not initialize discovery") }