How to generate url handler function on the fly

i want to build a server app that can handle lot of pages generated custom for every user/product and will carry a different [ https://0.0.0.0:0000/something/<some random name of product/page/person goes here>] , and these users/page keep on adding -i am trying to build a wordpress clone and shopping website template in go -

What you are looking for here is routing. See for example mux, which is a very popular package. http://www.gorillatoolkit.org/pkg/mux, and the examples there, like this

r := mux.NewRouter()
r.HandleFunc("/products/{key}", ProductHandler)

This is also possible using just the built in net/http, but you need to handle a bit more boilerplate code on your own. {key} is the important bit there, that’s the variable that will be passed to the function handling that request, and how you can decide what to show the user :slight_smile:

3 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.