Former-commit-id: d4eebea0b5849c574e2ffd4b0bb36e4380b14111
This commit is contained in:
Gerasimos (Makis) Maropoulos 2020-04-29 05:50:29 +03:00
parent 2a4043a3c2
commit ac08f53ba0
4 changed files with 94 additions and 86 deletions

View File

@ -93,7 +93,6 @@ func registerSubdomains(app *iris.Application) {
func newApp() *iris.Application {
app := iris.New()
app.Logger().SetLevel("debug")
registerErrors(app)
registerGamesRoutes(app)

View File

@ -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 != "" {

4
go.mod
View File

@ -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

143
iris.go
View File

@ -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)
}