GetIP returns either the IPv4 or IPv6 address from the parameter.
(name string)
| 604 | |
| 605 | // GetIP returns either the IPv4 or IPv6 address from the parameter. |
| 606 | func (pars Params) GetIP(name string) (net.IP, error) { |
| 607 | par, err := pars.findParam(name) |
| 608 | if err != nil { |
| 609 | return net.IP{}, err |
| 610 | } |
| 611 | if par.Type != params.IPv4 && par.Type != params.IPv6 { |
| 612 | return net.IP{}, fmt.Errorf("%q parameter is not an IP address", name) |
| 613 | } |
| 614 | v, ok := par.Value.(net.IP) |
| 615 | if !ok { |
| 616 | return net.IP{}, fmt.Errorf("unable to type cast %q parameter to net.IP value", name) |
| 617 | } |
| 618 | return v, nil |
| 619 | } |
| 620 | |
| 621 | // MustGetIP returns the IP address parameter or panics if an error occurs. |
| 622 | func (pars Params) MustGetIP(name string) net.IP { |
no test coverage detected