The middleware of @bobbybouwmann is perfect for this.
@Snapey I find the package a bit overkill. I only want to validate against an IP addresses. I also want to write the code a bit by myself so I can learn from it. From a package I don't learn anything