O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

For separating the handlers into modules, the code uses the ServeMux for each module, (rest and ui). The handling of URLs for the given module is defined relatively. This means if the final URL for the Handler should be /api/users, then the defined path within the module would be /users. The module itself would be set to /api/ URL.

The module is plugged into the main ServeMux pointer named mainMux by leveraging the StripPrefix function, which removes the module prefix. For instance, the REST module created by the restModule function, is plugged into the main ServeMux by StripPrefix("/api",restModule()). The handled URL within the module will then be /users, instead of /api/users.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required