diff --git a/_examples/routing/main.go b/_examples/routing/main.go index ae081109..d7537ea4 100644 --- a/_examples/routing/main.go +++ b/_examples/routing/main.go @@ -93,7 +93,6 @@ func registerSubdomains(app *iris.Application) { func newApp() *iris.Application { app := iris.New() - app.Logger().SetLevel("debug") registerErrors(app) registerGamesRoutes(app) diff --git a/core/router/route.go b/core/router/route.go index 97344eea..c23f99e9 100644 --- a/core/router/route.go +++ b/core/router/route.go @@ -386,18 +386,8 @@ func (r *Route) Trace(w io.Writer) { } path := r.Tmpl().Src - - if subdomain := r.Subdomain; subdomain != "" { - if path == "" { - path = "/" - } - - if subdomain == "*." { // wildcard. - subdomain = "subdomain" - } - - r.Description = fmt.Sprintf("%s", subdomain) - // path = fmt.Sprintf("%s %s", r.Subdomain, path) + if path == "" { + path = "/" } // @method: @path @@ -408,8 +398,22 @@ func (r *Route) Trace(w io.Writer) { // (@description) description := r.Description - if description == "" && r.Method == MethodNone { - description = "offline" + if description == "" { + if r.Method == MethodNone { + description = "offline" + } + + if subdomain := r.Subdomain; subdomain != "" { + if subdomain == "*." { // wildcard. + subdomain = "subdomain" + } + + if description == "offline" { + description += ", " + } + + description += subdomain + } } if description != "" { diff --git a/go.mod b/go.mod index efcb825e..aabb3938 100644 --- a/go.mod +++ b/go.mod @@ -20,9 +20,9 @@ require ( github.com/iris-contrib/pongo2 v0.0.1 github.com/iris-contrib/schema v0.0.1 github.com/json-iterator/go v1.1.9 - github.com/kataras/golog v0.0.12 + github.com/kataras/golog v0.0.13 github.com/kataras/neffos v0.0.15 - github.com/kataras/pio v0.0.5 + github.com/kataras/pio v0.0.6 github.com/kataras/sitemap v0.0.5 github.com/klauspost/compress v1.10.5 github.com/mediocregopher/radix/v3 v3.5.0 diff --git a/iris.go b/iris.go index 8243b303..2c78c51c 100644 --- a/iris.go +++ b/iris.go @@ -728,88 +728,93 @@ func (app *Application) Shutdown(ctx stdContext.Context) error { // app.Logger().Errorf("%s: %s", typ, err) // }) func (app *Application) Build() error { + if app.builded { + return nil + } + start := time.Now() + app.builded = true // even if fails. + rp := errgroup.New("Application Builder") + rp.Err(app.APIBuilder.GetReporter()) - if !app.builded { - app.builded = true - rp.Err(app.APIBuilder.GetReporter()) - - if app.defaultMode { // the app.I18n and app.View will be not available until Build. - if !app.I18n.Loaded() { - for _, s := range []string{"./locales/*/*", "./locales/*", "./translations"} { - if _, err := os.Stat(s); os.IsNotExist(err) { - continue - } - - if err := app.I18n.Load(s); err != nil { - continue - } - - app.I18n.SetDefault("en-US") - break + if app.defaultMode { // the app.I18n and app.View will be not available until Build. + if !app.I18n.Loaded() { + for _, s := range []string{"./locales/*/*", "./locales/*", "./translations"} { + if _, err := os.Stat(s); os.IsNotExist(err) { + continue } - } - if app.view.Len() == 0 { - for _, s := range []string{"./views", "./templates", "./web/views"} { - if _, err := os.Stat(s); os.IsNotExist(err) { - continue - } - - app.RegisterView(HTML(s, ".html")) - break + if err := app.I18n.Load(s); err != nil { + continue } + + app.I18n.SetDefault("en-US") + break } } - if app.I18n.Loaded() { - // {{ tr "lang" "key" arg1 arg2 }} - app.view.AddFunc("tr", app.I18n.Tr) - app.Router.WrapRouter(app.I18n.Wrapper()) - } + if app.view.Len() == 0 { + for _, s := range []string{"./views", "./templates", "./web/views"} { + if _, err := os.Stat(s); os.IsNotExist(err) { + continue + } - if n := app.view.Len(); n > 0 { - tr := "engines" - if n == 1 { - tr = tr[0 : len(tr)-1] + app.RegisterView(HTML(s, ".html")) + break } - - app.logger.Debugf("Application: %d registered view %s", n, tr) - // view engine - // here is where we declare the closed-relative framework functions. - // Each engine has their defaults, i.e yield,render,render_r,partial, params... - rv := router.NewRoutePathReverser(app.APIBuilder) - app.view.AddFunc("urlpath", rv.Path) - // app.view.AddFunc("url", rv.URL) - if err := app.view.Load(); err != nil { - rp.Group("View Builder").Err(err) - } - } - - if !app.Router.Downgraded() { - // router - if err := app.tryInjectLiveReload(); err != nil { - rp.Errf("LiveReload: init: failed: %v", err) - } - - if app.config.ForceLowercaseRouting { - app.Router.WrapRouter(func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) { - r.URL.Path = strings.ToLower(r.URL.Path) - next(w, r) - }) - } - - // create the request handler, the default routing handler - routerHandler := router.NewDefaultHandler(app.config) - err := app.Router.BuildRouter(app.ContextPool, routerHandler, app.APIBuilder, false) - if err != nil { - rp.Err(err) - } - // re-build of the router from outside can be done with - // app.RefreshRouter() } } + if app.I18n.Loaded() { + // {{ tr "lang" "key" arg1 arg2 }} + app.view.AddFunc("tr", app.I18n.Tr) + app.Router.WrapRouter(app.I18n.Wrapper()) + } + + if n := app.view.Len(); n > 0 { + tr := "engines" + if n == 1 { + tr = tr[0 : len(tr)-1] + } + + app.logger.Debugf("Application: %d registered view %s", n, tr) + // view engine + // here is where we declare the closed-relative framework functions. + // Each engine has their defaults, i.e yield,render,render_r,partial, params... + rv := router.NewRoutePathReverser(app.APIBuilder) + app.view.AddFunc("urlpath", rv.Path) + // app.view.AddFunc("url", rv.URL) + if err := app.view.Load(); err != nil { + rp.Group("View Builder").Err(err) + } + } + + if !app.Router.Downgraded() { + // router + if err := app.tryInjectLiveReload(); err != nil { + rp.Errf("LiveReload: init: failed: %v", err) + } + + if app.config.ForceLowercaseRouting { + app.Router.WrapRouter(func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) { + r.URL.Path = strings.ToLower(r.URL.Path) + next(w, r) + }) + } + + // create the request handler, the default routing handler + routerHandler := router.NewDefaultHandler(app.config) + err := app.Router.BuildRouter(app.ContextPool, routerHandler, app.APIBuilder, false) + if err != nil { + rp.Err(err) + } + // re-build of the router from outside can be done with + // app.RefreshRouter() + } + + // if end := time.Since(start); end.Seconds() > 5 { + app.logger.Debugf("Application: build took %s", time.Since(start)) + return errgroup.Check(rp) }