Esempio n. 1
0
File: main.go Progetto: micro/db-srv
func main() {
	service := micro.NewService(
		micro.Name("go.micro.srv.db"),
		micro.Version("latest"),

		micro.Flags(
			cli.StringFlag{
				Name:   "database_service_namespace",
				EnvVar: "DATABASE_SERVICE_NAMESPACE",
				Usage:  "The namespace used when looking up databases in registry e.g go.micro.db",
			},
		),

		micro.Action(func(c *cli.Context) {
			if len(c.String("database_service_namespace")) > 0 {
				db.DBServiceNamespace = c.String("database_service_namespace")
			}
		}),
	)

	service.Init(
		// init the db
		micro.BeforeStart(func() error {
			return db.Init(service.Client().Options().Selector)
		}),
	)

	proto.RegisterDBHandler(service.Server(), new(handler.DB))

	if err := service.Run(); err != nil {
		log.Fatal(err)
	}
}
Esempio n. 2
0
File: db.go Progetto: micro/platform
func srv(ctx *cli.Context) {
	service := micro.NewService(
		micro.Name("go.micro.srv.db"),
		micro.RegisterTTL(
			time.Duration(ctx.GlobalInt("register_ttl"))*time.Second,
		),
		micro.RegisterInterval(
			time.Duration(ctx.GlobalInt("register_interval"))*time.Second,
		),
	)

	if len(ctx.String("database_service_namespace")) > 0 {
		db.DBServiceNamespace = ctx.String("database_service_namespace")
	}

	proto.RegisterDBHandler(service.Server(), new(handler.DB))

	if err := db.Init(service.Client().Options().Selector); err != nil {
		log.Fatal(err)
	}

	if err := service.Run(); err != nil {
		log.Fatal(err)
	}
}