specificity returns len(s) minus any wildcards (*) and placeholders ({...}). Basically, it's a length count that penalizes the use of wildcards and placeholders. This is useful for comparing hostnames and paths. However, wildcards in paths are not a sure answer to the question of specificity. For ex
(s string)
| 1724 | // 'a.example.com', but is '/a' more or less specific |
| 1725 | // than '/a*'? |
| 1726 | func specificity(s string) int { |
| 1727 | l := len(s) - strings.Count(s, "*") |
| 1728 | for len(s) > 0 { |
| 1729 | start := strings.Index(s, "{") |
| 1730 | if start < 0 { |
| 1731 | return l |
| 1732 | } |
| 1733 | end := strings.Index(s[start:], "}") + start + 1 |
| 1734 | if end <= start { |
| 1735 | return l |
| 1736 | } |
| 1737 | l -= end - start |
| 1738 | s = s[end:] |
| 1739 | } |
| 1740 | return l |
| 1741 | } |
| 1742 | |
| 1743 | type counter struct { |
| 1744 | n *int |
no outgoing calls