コード例 #1
0
ファイル: main.go プロジェクト: yonglehou/micro
func main() {
	app := cmd.App()
	app.Commands = append(app.Commands, api.Commands()...)
	app.Commands = append(app.Commands, cli.Commands()...)
	app.Commands = append(app.Commands, car.Commands()...)
	app.Commands = append(app.Commands, web.Commands()...)
	app.Action = func(context *ccli.Context) { ccli.ShowAppHelp(context) }

	setup(app)

	cmd.Init(
		cmd.Name("micro"),
		cmd.Description("A microservices toolkit"),
		cmd.Version("latest"),
	)
}
コード例 #2
0
ファイル: main.go プロジェクト: micro/platform
func main() {
	app := cmd.App()
	app.Commands = append(app.Commands, auth.Commands()...)
	app.Commands = append(app.Commands, config.Commands()...)
	app.Commands = append(app.Commands, discovery.Commands()...)
	app.Commands = append(app.Commands, db.Commands()...)
	app.Commands = append(app.Commands, event.Commands()...)
	app.Commands = append(app.Commands, kv.Commands()...)
	//	app.Commands = append(app.Commands, log.Commands()...)
	//	app.Commands = append(app.Commands, metrics.Commands()...)
	app.Commands = append(app.Commands, monitor.Commands()...)
	app.Commands = append(app.Commands, router.Commands()...)
	//	app.Commands = append(app.Commands, sync.Commands()...)
	app.Commands = append(app.Commands, trace.Commands()...)
	app.Action = func(context *ccli.Context) { ccli.ShowAppHelp(context) }

	setup(app)

	cmd.Init(
		cmd.Name("os"),
		cmd.Description("A microservices operating system"),
		cmd.Version("latest"),
	)
}
コード例 #3
0
ファイル: service.go プロジェクト: micro/go-web
func (s *service) Init(opts ...Option) error {
	app := cmd.App()

	app.Flags = append(app.Flags,
		cli.IntFlag{
			Name:   "register_ttl",
			EnvVar: "MICRO_REGISTER_TTL",
			Usage:  "Register TTL in seconds",
		},
		cli.IntFlag{
			Name:   "register_interval",
			EnvVar: "MICRO_REGISTER_INTERVAL",
			Usage:  "Register interval in seconds",
		},
	)

	before := app.Before

	app.Before = func(ctx *cli.Context) error {
		if ttl := ctx.Int("register_ttl"); ttl > 0 {
			s.opts.RegisterTTL = time.Duration(ttl) * time.Second
		}

		if interval := ctx.Int("register_interval"); interval > 0 {
			s.opts.RegisterInterval = time.Duration(interval) * time.Second
		}

		if name := ctx.String("server_name"); len(name) > 0 {
			s.opts.Name = name
		}

		if ver := ctx.String("server_version"); len(ver) > 0 {
			s.opts.Version = ver
		}

		if id := ctx.String("server_id"); len(id) > 0 {
			s.opts.Id = id
		}

		if addr := ctx.String("server_address"); len(addr) > 0 {
			s.opts.Address = addr
		}

		if adv := ctx.String("server_advertise"); len(adv) > 0 {
			s.opts.Advertise = adv
		}

		return before(ctx)
	}

	cmd.Init()

	for _, o := range opts {
		o(&s.opts)
	}

	srv := s.genSrv()
	srv.Endpoints = s.srv.Endpoints
	s.srv = srv

	return nil
}