Use the whitelist package for IP access control
masterThe whitelist package provides mechanisms to permit or deny access based on IP addresses. The core interface is the ACL type, which features a Permitted(net.IP) bool method to check if an address is whitelisted.
There are two primary specialized types:
HostACL: Manages individual IP addresses usingAdd(net.IP)andRemove(net.IP).NetACL: Manages network ranges usingAdd(*net.IPNet)andRemove(*net.IPNet).
Available implementations:
Basic: A host-based whitelister using amap[string]boolandsync.Mutex.BasicNet: A network-based whitelister. Note thatBasicNetrequires exact network matches forAddandRemove; it does not detect subsets or supersets (e.g., removing a subnet will not remove a larger network that contains it).HostStubandNetStub: Stand-in implementations that always permit access and log warnings.