code: func CheckIPWhitelist(remoteAddr string, ipRange string) (bool, error) {
  	// Extract IP address from remote address.
  
  	ip := remoteAddr
  
  	if strings.LastIndex(remoteAddr, ":") != -1 {
  		ip = remoteAddr[0:strings.LastIndex(remoteAddr, ":")]
  	}
  
  	ip = strings.TrimSpace(ip)
  
  	// IPv6 addresses will likely be surrounded by [], so don't forget to remove those.
  
  	if strings.HasPrefix(ip, "[") && strings.HasSuffix(ip, "]") {
  		ip = ip[1 : len(ip)-1]
  	}
  
  	parsedIP := net.ParseIP(strings.TrimSpace(ip))
  
  	if parsedIP == nil {
  		return false, fmt.Errorf("invalid IP address found in remote address '%s'", remoteAddr)
  	}
  
  	// Extract IP range in CIDR form.  If a single IP address is provided, turn it into CIDR form.
  
  	ipRange = strings.TrimSpace(ipRange)
  
  	if !strings.Contains(ipRange, "/") {
  		ipRange = ipRange + "/32"
  	}
  
  	_, cidr, err := net.ParseCIDR(ipRange)
  
  	if err != nil {
  		return false, err
  	}
  
  	return cidr.Contains(parsedIP), nil
  }
docs: // CheckIPWhitelist makes sure the provided remote address (of the form IP:port) falls within the provided IP range
  // (in CIDR form or a single IP address).