Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var BusCmd = &cobra.Command{ Use: "bus", Short: "事件总线", Long: `事件总线 客户端`, RunE: func(cmd *cobra.Command, args []string) error { err := zap.DevelopmentSetup() if err != nil { return err } log := zap.L().Named("Bus") var ( pub bus.PubManager sub bus.SubManager ) switch busType { case "nats": nc.Servers = servers nc.Username = username nc.Password = password ins, err := nats.NewBroker(nc) if err != nil { return err } ins.Debug(log) pub = ins sub = ins case "kafka": kc.Hosts = servers kc.Username = username kc.Password = password kp, err := kafka.NewPublisher(kc) if err != nil { return err } kp.Debug(log) ks, err := kafka.NewSubscriber(kc) if err != nil { return err } ks.Debug(log) default: return fmt.Errorf("unknown bus type: %s", busType) } switch mod { case "pub": if err := pub.Connect(); err != nil { return fmt.Errorf("connect to bus error, %s", err) } for { var eventJSON string randomE, err := newRandomEvent() if err != nil { return err } err = survey.AskOne( &survey.Input{ Message: "请输入JSON格式事件:", Default: randomE, }, &eventJSON, survey.WithValidator(survey.Required), ) if err != nil { return err } oe := &event.OperateEventData{} err = json.Unmarshal([]byte(eventJSON), oe) if err != nil { return err } e, err := event.NewOperateEvent(oe) if err != nil { return err } if err := pub.Pub(topic, e); err != nil { log.Errorf("pub event error, %s", err) } fmt.Println() } case "sub": if err := sub.Connect(); err != nil { return fmt.Errorf("connect to bus error, %s", err) } sub.Sub(topic, func(topic string, e *event.Event) error { fmt.Println(e) return nil }) time.Sleep(10 * time.Minute) default: return fmt.Errorf("unknown mod: %s", mod) } return nil }, }
BusCmd 枚举生成器
View Source
var EnumCmd = &cobra.Command{ Use: "enum", Short: "枚举生成器", Long: `枚举生成器`, RunE: func(cmd *cobra.Command, args []string) error { code, err := enum.G.Generate() if err != nil { return err } if len(code) == 0 { return nil } fname := os.Getenv("GOFILE") genFile := fname[0:len(fname)-len(path.Ext(fname))] + "_enum_generate.go" return ioutil.WriteFile(genFile, code, 0644) }, }
EnumCmd 枚举生成器
View Source
var InitCmd = &cobra.Command{ Use: "init", Short: "初始化", Long: `初始化一个mcube项目`, RunE: func(cmd *cobra.Command, args []string) error { p, err := project.LoadConfigFromCLI() if err != nil { return err } err = p.Init() if err != nil { return err } return nil }, }
InitCmd 初始化系统
View Source
var RootCmd = &cobra.Command{ Use: "mcube", Short: "mcube 分布式服务构建工具", Long: `mcube ...`, RunE: func(cmd *cobra.Command, args []string) error { return errors.New("no flags find") }, }
RootCmd represents the base command when called without any subcommands
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.