M
M
Michael2016-01-28 22:07:30
go
Michael, 2016-01-28 22:07:30

How to make something like blueprint flask using gorilla mux??

Hello, in the flask everything just has blueprints and in the main app we just hang each blueprint on its sub-urls

app.register_blueprint('/', a_BP)
 app.register_blueprint('/b', b_BP)
 app.register_blueprint('/c', c_BP)
 app.register_blueprint('/d'', d_BP)

and inside the blueprints themselves we already hang the routes as we want, how to organize a similar routing in several files in the gorilla mux toolkit in go? all the tutorials that I came across show how to make everything cool in 1 file without subrouters ... that is, not at all what you need.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey, 2016-01-29
@nextel

In theory , Subrouter will suit you . You can do something like this:

import (
  "blue_prints/bp1"
  "blue_prints/bp2"
)
r := mux.NewRouter()
sub_router1 := r.PathPrefix("/bp1").Subrouter()
sub_router2 := r.PathPrefix("/bp2").Subrouter()
bp1.Register(sub_router1)
bp2.Register(sub_router2)

And inside the Register function , you can already hang your routes.

M
Michael, 2016-01-31
@nextel

I found an approach similar to yours, only with unlimited space)
https://groups.google.com/forum/#!topic/gorilla-we...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question