You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

watch.go 961 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package sysevent
  2. import (
  3. "bytes"
  4. "encoding/json"
  5. "fmt"
  6. "github.com/spf13/cobra"
  7. se "github.com/tmaxmax/go-sse"
  8. cliapi "gitlink.org.cn/cloudream/jcs-pub/client/sdk/api/v1"
  9. "gitlink.org.cn/cloudream/jcs-pub/jcsctl/cmd"
  10. )
  11. func init() {
  12. var opt watchOpt
  13. cmd := cobra.Command{
  14. Use: "watch",
  15. Args: cobra.ExactArgs(0),
  16. RunE: func(c *cobra.Command, args []string) error {
  17. ctx := cmd.GetCmdCtx(c)
  18. return watch(c, ctx, opt, args)
  19. },
  20. }
  21. SysEventCmd.AddCommand(&cmd)
  22. }
  23. type watchOpt struct {
  24. }
  25. func watch(c *cobra.Command, ctx *cmd.CommandContext, opt watchOpt, args []string) error {
  26. resp, err := ctx.Client.SysEvent().Watch(cliapi.SysEventWatch{})
  27. if err != nil {
  28. return fmt.Errorf("begin watch : %v", err)
  29. }
  30. defer resp.Stream.Close()
  31. se.Read(resp.Stream, nil)(func(e se.Event, err error) bool {
  32. buf := bytes.NewBuffer(nil)
  33. json.Indent(buf, []byte(e.Data), "", " ")
  34. fmt.Println(buf.String())
  35. return true
  36. })
  37. return nil
  38. }

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。