Endpoints with dynamic paths

Pattern matching for the http package in the Go standard library isn't the most comprehensive and fully featured implementation out there. For example, Ruby on Rails makes it much easier to have dynamic segments inside the path. You could map the route like this:

"auth/:action/:provider_name" 

Rails then provides a data map (or dictionary) containing the values that it automatically extracted from the matched path. So if you visit auth/login/google, then params[:provider_name] would equal google and params[:action] would equal login.

The most the http package lets us specify by default is a path prefix, which we can make use of by leaving a trailing slash at the end of the pattern:

"auth/" 

We would then have to manually ...

Get Go Programming Blueprints - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.