Ejemplo n.º 1
0
func main() {
	fmt.Println("Otsimo Registry")

	app := cli.NewApp()
	app.Version = Version
	app.Usage = "Otsimo Registry Server"
	app.Name = "registry"
	app.Authors = []cli.Author{
		{
			Name:  "Sercan Değirmenci",
			Email: "*****@*****.**",
		},
	}
	dnames := db.GetDriverNames()
	snames := storage.GetDriverNames()

	var flags []cli.Flag

	flags = []cli.Flag{
		cli.IntFlag{Name: "port", Destination: &config.Port, Value: registry.DefaultPort, Usage: "grpc server port"},
		cli.IntFlag{Name: "grpc-port", Destination: &config.GrpcPort, Value: registry.DefaultGrpcPort, Usage: "grpc server port"},
		cli.StringFlag{Name: "db", Value: "none", Usage: fmt.Sprintf("the db driver. Available drivers: %s", strings.Join(dnames, ", "))},
		cli.StringFlag{Name: "storage", Value: "disk", Usage: fmt.Sprintf("the storage driver. Available drivers: %s", strings.Join(snames, ", "))},
		cli.StringFlag{Name: "tls-cert-file", Destination: &config.TlsCertFile, Value: "", Usage: "the server's certificate file for TLS connection"},
		cli.StringFlag{Name: "tls-key-file", Destination: &config.TlsKeyFile, Value: "", Usage: "the server's private key file for TLS connection"},
		cli.StringFlag{Name: "search-service-url", Destination: &config.SearchServiceUrl, Value: "127.0.0.1:18856", Usage: "search service url"},
		cli.BoolFlag{Name: "enable-search, e", Destination: &config.EnableSearch, Usage: "enable searching"},
		cli.StringFlag{Name: "static", Destination: &config.StaticPath, Value: "./disk", Usage: "the path where server will serve static files"},
		cli.StringFlag{Name: "client-id", Destination: &config.ClientID, Value: "", Usage: "client id"},
		cli.StringFlag{Name: "client-secret", Destination: &config.ClientSecret, Value: "", Usage: "client secret"},
		cli.StringFlag{Name: "discovery", Destination: &config.AuthDiscovery, Value: "https://connect.otsimo.com", Usage: "auth discovery url"},
		cli.BoolFlag{Name: "no-https", Usage: "do not enable tls for http server, use this if server running behind a reverse proxy"},
	}
	flags = addEnvs("OTSIMO_REGISTRY", flags)
	for _, d := range dnames {
		flags = append(flags, db.GetDriver(d).Flags...)
	}
	for _, d := range snames {
		flags = append(flags, storage.GetDriver(d).Flags...)
	}
	flags = append(flags, cli.BoolFlag{Name: "debug, d", Destination: &config.Debug, Usage: "enable verbose log", EnvVar: EnvDebugName})

	app.Flags = flags
	app.Action = RunAction
	log.Infoln("running", app.Name, "version:", app.Version)
	if err := app.Run(os.Args); err != nil {
		log.Fatalln(err)
	}
}
Ejemplo n.º 2
0
func RunAction(c *cli.Context) error {
	config.SecureHttp = !c.Bool("no-https")

	if config.Debug {
		log.SetLevel(log.DebugLevel)
	}
	//find driver name
	sname := c.String("db")
	if sname == "" || sname == "none" {
		return fmt.Errorf("main.go: db flag='%s' is invalid", sname)
	}
	sdname := c.String("storage")
	if sdname == "" || sdname == "none" {
		return fmt.Errorf("main.go: storage flag='%s' is invalid", sdname)
	}

	//insert here stırage driver
	sdriver := storage.GetDriver(sdname)
	if sdriver == nil {
		return fmt.Errorf("main.go: storage driver '%s' not found\n", sdname)
	}

	//load db driver
	store, err := sdriver.New(c)
	if err != nil {
		return fmt.Errorf("main.go: unable to create a new db driver: %v", err)
	}

	//get driver
	driver := db.GetDriver(sname)
	if driver == nil {
		return fmt.Errorf("main.go: db driver '%s' not found", sname)
	}

	//load db driver
	s, err := driver.New(c)
	if err != nil {
		return fmt.Errorf("main.go: unable to create a new db driver: %v", err)
	}

	server := registry.NewServer(config, s, store)
	go server.ListenHTTP()
	return server.ListenGRPC()
}