(p string)
| 31 | } |
| 32 | |
| 33 | func ParsePreference(p string) (Preference, error) { |
| 34 | var res Preference |
| 35 | switch lp := strings.ToLower(p); lp { |
| 36 | case "none", "nothing", "any", "anything": |
| 37 | res = PreferenceNothing |
| 38 | case "ipv4", "ip4", "v4", "4": |
| 39 | res = PreferenceIPv4 |
| 40 | case "ipv6", "ip6", "v6", "6": |
| 41 | res = PreferenceIPv6 |
| 42 | default: |
| 43 | return 0, fmt.Errorf("unknown preference specification %q", p) |
| 44 | } |
| 45 | return res, nil |
| 46 | } |
| 47 | |
| 48 | func boolToInt(x bool) int { |
| 49 | if x { |