ParseShardIndex parses a canonical shard key value ("shard ") back into its index. Non-canonical values (including the legacy "tenants" bucket) return ok=false.
(s string)
| 101 | // its index. Non-canonical values (including the legacy "tenants" bucket) |
| 102 | // return ok=false. |
| 103 | func ParseShardIndex(s string) (int, bool) { |
| 104 | rest, found := strings.CutPrefix(s, shardPrefix) |
| 105 | if !found || rest == "" { |
| 106 | return 0, false |
| 107 | } |
| 108 | i, err := strconv.Atoi(rest) |
| 109 | if err != nil || i < 0 || ShardName(i) != s { |
| 110 | return 0, false |
| 111 | } |
| 112 | return i, true |
| 113 | } |
| 114 | |
| 115 | // ParseShardDeploymentIndex parses a shard Deployment name back into its |
| 116 | // shard index. |