Interval is [start, stop), but the GTID string's format is [n] or [n1-n2], closed interval
(str string)
| 25 | |
| 26 | // Interval is [start, stop), but the GTID string's format is [n] or [n1-n2], closed interval |
| 27 | func parseInterval(str string) (i Interval, err error) { |
| 28 | p := strings.Split(str, "-") |
| 29 | switch len(p) { |
| 30 | case 1: |
| 31 | i.Start, err = strconv.ParseInt(p[0], 10, 64) |
| 32 | i.Stop = i.Start + 1 |
| 33 | case 2: |
| 34 | i.Start, err = strconv.ParseInt(p[0], 10, 64) |
| 35 | if err == nil { |
| 36 | i.Stop, err = strconv.ParseInt(p[1], 10, 64) |
| 37 | i.Stop++ |
| 38 | } |
| 39 | default: |
| 40 | err = errors.Errorf("invalid interval format, must n[-n]") |
| 41 | } |
| 42 | |
| 43 | if err != nil { |
| 44 | return |
| 45 | } |
| 46 | |
| 47 | if i.Stop <= i.Start { |
| 48 | err = errors.Errorf("invalid interval format, must n[-n] and the end must >= start") |
| 49 | } |
| 50 | |
| 51 | return |
| 52 | } |
| 53 | |
| 54 | func (i Interval) String() string { |
| 55 | if i.Stop == i.Start+1 { |
no outgoing calls