progress.go 527 B

1234567891011121314151617181920212223242526272829303132
  1. package utils
  2. import "github.com/cheggaaa/pb/v3"
  3. type ProgressEvent int
  4. const (
  5. NoAvailableIPFound ProgressEvent = iota
  6. AvailableIPFound
  7. NormalPing
  8. )
  9. type Bar struct {
  10. *pb.ProgressBar
  11. }
  12. func NewBar(count int) *Bar {
  13. return &Bar{pb.Simple.Start(count)}
  14. }
  15. func handleProgressGenerator(pb *pb.ProgressBar) func(e ProgressEvent) {
  16. return func(e ProgressEvent) {
  17. switch e {
  18. case NoAvailableIPFound:
  19. // pb.Add(pingTime)
  20. case AvailableIPFound:
  21. // pb.Add(failTime)
  22. case NormalPing:
  23. pb.Increment()
  24. }
  25. }
  26. }