title: Best way to check user permissions in a Go web app router
body: <p>My web app has URLs at three access levels:</p>
  
  <ul>
  <li>Those accessible by anyone (login page and static assets)</li>
  <li>Those accessible regular users and admins who are logged in</li>
  <li>Those accessible only by admins who are logged in</li>
  </ul>
  
  <p>I should specify the minimum access level for each URL pattern in my router, so that people below that level are blocked. (I suppose they should get HTTP error 401 or 403.)</p>
  
  <p>How do I best implement these checks so that I don't have to remember to put them in every URL handler function separately (which is very easy to forget)? Ideally I'd like to do something like this:</p>
  
  <pre><code>router.Get("/someRegularPage", regularAccess(handleSomeRegularPage))
  router.Get("/someAdminPage", adminAccess(handleSomeAdminPage))
  router.Get("/", publicAccess(handleLoginPage))
  </code></pre>
  
  <p>Is there some semi-standard middleware to do this and how does that work? How hard would it be to write my own?</p>
  
  <p>Additionally, it would be great if the default permission was to deny access to everybody in case I forget to specify the access level for some URL. A compiler warning or error would be ideal.</p>