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 } var e *event.Event switch contentType { case "json": e, err = event.NewJsonOperateEvent(oe) default: e, err = event.NewProtoOperateEvent(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.Printf("sub event: %s\n", 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 { if len(args) == 0 { return fmt.Errorf("input file is mandatory, see: -help") } matchedFiles := []string{} for _, v := range args { files, err := filepath.Glob(v) if err != nil { return err } if strings.HasSuffix(v, ".go") { matchedFiles = append(matchedFiles, files...) } } if len(matchedFiles) == 0 { return fmt.Errorf("no file matched") } for _, path := range matchedFiles { code, err := enum.G.Generate(path) if err != nil { return err } if len(code) == 0 { continue } var genFile = "" if strings.HasSuffix(path, ".pb.go") { genFile = strings.ReplaceAll(path, ".pb.go", "_enum.pb.go") } else { genFile = strings.ReplaceAll(path, ".go", "_enum.go") } err = ioutil.WriteFile(genFile, code, 0644) if err != nil { return err } } return nil }, }
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 { if err == terminal.InterruptErr { fmt.Println("项目初始化取消") return nil } return err } err = p.Init() if err != nil { return err } return nil }, }
InitCmd 初始化系统
View Source
var InjectTagCmd = &cobra.Command{ Use: "inject-tag", Short: "tag 注入", Long: `tag 注入`, RunE: func(cmd *cobra.Command, args []string) error { if len(args) == 0 { return fmt.Errorf("input file is mandatory, see: -help") } matchedFiles := []string{} for _, v := range args { files, err := filepath.Glob(v) if err != nil { return err } matchedFiles = append(matchedFiles, files...) } if len(matchedFiles) == 0 { return fmt.Errorf("no file matched") } for _, path := range matchedFiles { if !strings.HasSuffix(path, ".go") { continue } areas, err := inject_tag.ParseFile(path, []string{}) if err != nil { log.Fatal(err) } if err = inject_tag.WriteFile(path, areas); err != nil { log.Fatal(err) } } return nil }, }
EnumCmd 枚举生成器
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.