Is it good practice in golang to write custom handlers used just in specific endpoints?
I.e. given following endpoint: /users/someusername/items/1
I know I'll need user information (for user with id: someusername
) and also information for item with id: 1
. Would it be good practice to create 2 custom handlers, one which will handle pulling user data and putting it in context (and exit on error with proper response) and another one for pulling item data (and also putting it in context to use by further handlers)? And then using them as follow:
userItemsHandler := userContextHandler(itemConextHandler(ItemGET))
r.Handle("/users/{username}/items/{itemId}", userItemsHandler).Methods("PUT")
In example, custom handler for items will be probably used in only couple endpoints, though I can see multiple usage for user handler.
Thanks in advance for answers.