// Provision parses m's IP ranges, either from IP or CIDR expressions.
Provision parses m's IP ranges, either from IP or CIDR expressions.
// Provision parses m ' s IP ranges either from IP or CIDR expressions .
func (m *MatchIP) Provision(ctx caddy.Context) error {
	for _, str := range m.Ranges {
		if strings.Contains(str, "/") {
			_, ipNet, err := net.ParseCIDR(str)
			if err != nil {
				return fmt.Errorf("parsing CIDR expression: %v", err)
			}
			m.cidrs = append(m.cidrs, ipNet)
		} else {
			ip := net.ParseIP(str)
			if ip == nil {
				return fmt.Errorf("invalid IP address: %s", str)
			}
			mask := len(ip) * 8
			m.cidrs = append(m.cidrs, &net.IPNet{
				IP:   ip,
				Mask: net.CIDRMask(mask, mask),
			})
		}
	}
	return nil
}
func ( m * MatchIP ) Provision ( ctx caddy . Context ) error { for _ , str := range m . Ranges { if strings . Contains ( str , " " ) { _ , ipNet , err := net . ParseCIDR ( str ) if err != nil { return fmt . Errorf ( " " , err ) } m . cidrs = append ( m . cidrs , ipNet ) } else { ip := net . ParseIP ( str ) if ip == nil { return fmt . Errorf ( " " , str ) } mask := len ( ip ) * 8 m . cidrs = append ( m . cidrs , & net . IPNet { IP : ip , Mask : net . CIDRMask ( mask , mask ) , } ) } } return nil }
Provision parses m's IP ranges, either from IP or CIDR expressions.
Provision parses m ' s IP ranges either from IP or CIDR expressions .