maintain (refactoring): unit testability of router

This commit is contained in:
Mickael Kerjean
2023-06-07 17:57:51 +10:00
parent a2c0323e8d
commit 5eadfac2ae

View File

@ -21,11 +21,10 @@ import (
var EmbedPluginList []byte var EmbedPluginList []byte
func main() { func main() {
app := App{} start(build(App{}))
Init(app)
} }
func Init(a App) { func build(a App) *mux.Router {
var ( var (
r *mux.Router = mux.NewRouter() r *mux.Router = mux.NewRouter()
middlewares []Middleware middlewares []Middleware
@ -122,6 +121,10 @@ func Init(a App) {
r.PathPrefix("/admin").Handler(http.HandlerFunc(NewMiddlewareChain(IndexHandler, middlewares, a))).Methods("GET") r.PathPrefix("/admin").Handler(http.HandlerFunc(NewMiddlewareChain(IndexHandler, middlewares, a))).Methods("GET")
r.PathPrefix("/").Handler(http.HandlerFunc(NewMiddlewareChain(IndexHandler, middlewares, a))).Methods("GET", "POST") r.PathPrefix("/").Handler(http.HandlerFunc(NewMiddlewareChain(IndexHandler, middlewares, a))).Methods("GET", "POST")
return r
}
func start(routes *mux.Router) {
// Routes are served via plugins to avoid getting stuck with plain HTTP. The idea is to // Routes are served via plugins to avoid getting stuck with plain HTTP. The idea is to
// support many more protocols in the future: HTTPS, HTTP2, TOR or whatever that sounds // support many more protocols in the future: HTTPS, HTTP2, TOR or whatever that sounds
// fancy I don't know much when this got written: IPFS, solid, ... // fancy I don't know much when this got written: IPFS, solid, ...
@ -135,7 +138,7 @@ func Init(a App) {
for _, obj := range Hooks.Get.Starter() { for _, obj := range Hooks.Get.Starter() {
wg.Add(1) wg.Add(1)
go func() { go func() {
obj(r) obj(routes)
wg.Done() wg.Done()
}() }()
} }