Acacia is lightweight package that will help you to route http server. Acacia route the path based on tree data structure. This package also support parameters in the path, so it will help you to build http routing with some parameters. in the path
$ go get github.com/MeiSastraJayadi/acacia
router := multiplexer.NewRouter("/")
SetPrefix will add a prefix into the router path. the parameter that will be accept in function SetPrefix is just a string
router := multiplexer.NewRouter("/")
router = router.SetPrefix("product")
With Router.Methods(), some methods will be added into the router. The methods can be added more than just one method if the router can handle more than one methods
router := multiplexer.NewRouter("/")
routerPost := router.Methods(http.MethodsPost)
router := multiplexer.NewRouter("/")
routerPost := router.Methods(http.MethodsPost, http.MethodGet)
router := multiplexer.NewRouter("/")
routerPost := router.Methods(http.MethodsPost, http.MethodGet)
subrouter := multiplexer.NewRouter("/")
subrouter.SetPrefix("product")
subrouterPost := subrouter.Methods(http.MethodGet)
router.SubRouter(subrouter)
You can specify a parameter in path, and you can use the parameter to get the value from URL path. To do that what you can do is
router := multiplexer.NewRouter("/").SetPrefix("category")
router.Methods(http.MethodGet).HandleFunc("/{path_slug:slug}", thePathHandlerFunction)
In code abobe we create parameter in the path and named it as path_slug, to set parameter you should writer it as {name_of_parameter:type_of_paremeter}
func someHandlerFunc(w http.ResponseWriter, r *http.Request) {
vr := multiplexer.Vars(r)
path_slug := vr["path_slug"] // Get path_slug parameter from the URL path
}