Пример #1
0
func RunAction(c *cli.Context) error {
	config.GrpcPort = c.Int("port")
	config.Debug = c.Bool("debug")
	config.TlsCertFile = c.String("tls-cert-file")
	config.TlsKeyFile = c.String("tls-key-file")
	config.ClientID = c.String("client-id")
	config.ClientSecret = c.String("client-secret")
	config.AuthDiscovery = c.String("discovery")
	config.RedisAddr = c.String("redis-addr")
	config.RedisDB = c.Int("redis-db")
	config.RedisPassword = c.String("redis-password")
	config.RedisMasterName = c.String("redis-master")
	config.RedisSentinel = c.Bool("redis-sentinel")
	storage := c.String("storage")

	if config.Debug {
		log.SetLevel(log.DebugLevel)
	}

	if storage == "" || storage == "none" {
		cli.ShowAppHelp(c)
		return errors.New("storage is not set")
	}
	driver := drivers.GetDriver(storage)
	if driver == nil {
		return fmt.Errorf("main.go: storage driver '%s' not found\n", storage)
	}

	s, err := driver.New(c)
	if err != nil {
		return fmt.Errorf("main.go: error while creating new storage driver: %v", err)
	}
	srv := listener.NewServer(config, s)
	return srv.ListenGRPC()
}
Пример #2
0
func main() {
	flags := make([]cli.Flag, 0)
	dnames := drivers.GetDriverNames()

	app := cli.NewApp()
	app.Name = "listener"
	app.Version = Version
	app.Usage = "A simple service to listening events from apps"
	app.Authors = []cli.Author{
		{
			Name:  "Sercan Degirmenci",
			Email: "*****@*****.**",
		},
	}
	flags = append([]cli.Flag{
		cli.IntFlag{Name: "port", Value: config.GrpcPort, Usage: "App port"},
		cli.IntFlag{Name: "health-port", Value: config.HealthPort, Usage: "Health check port"},
		cli.StringFlag{Name: "storage, s", Value: "none", Usage: fmt.Sprintf("The storage driver. Available drivers: %s", strings.Join(dnames, ", "))},
		cli.StringFlag{Name: "tls-cert-file", Value: "", Usage: "the server's certificate file for TLS connection"},
		cli.StringFlag{Name: "tls-key-file", Value: "", Usage: "the server's private key file for TLS connection"},
		cli.StringFlag{Name: "client-id", Value: "", Usage: "client id"},
		cli.StringFlag{Name: "client-secret", Value: "", Usage: "client secret"},
		cli.StringFlag{Name: "discovery", Value: "https://connect.otsimo.com", Usage: "auth discovery url"},
		cli.StringFlag{Name: "redis-addr", Value: config.RedisAddr, Usage: "redis address"},
		cli.StringFlag{Name: "redis-password", Value: config.RedisPassword, Usage: "redis password"},
		cli.StringFlag{Name: "redis-master", Value: config.RedisMasterName, Usage: "redis master name"},
		cli.BoolFlag{Name: "redis-sentinel", Usage: "enable redis sentinel"},
		cli.IntFlag{Name: "redis-db", Value: config.RedisDB, Usage: "redis db"},
		cli.BoolFlag{Name: "debug, d", Usage: "Verbose output"},
	})
	flags = withEnvs("OTSIMO_LISTENER", flags)
	for _, d := range dnames {
		flags = append(flags, drivers.GetDriver(d).Flags...)
	}
	app.Flags = flags
	app.Action = RunAction

	log.Infoln("running", app.Name, "version:", app.Version)
	if err := app.Run(os.Args); err != nil {
		log.Fatal(err)
	}
}