mirror of
https://github.com/kataras/iris.git
synced 2025-03-15 02:26:29 +01:00
minor
Former-commit-id: d4eebea0b5849c574e2ffd4b0bb36e4380b14111
This commit is contained in:
parent
2a4043a3c2
commit
ac08f53ba0
|
@ -93,7 +93,6 @@ func registerSubdomains(app *iris.Application) {
|
||||||
|
|
||||||
func newApp() *iris.Application {
|
func newApp() *iris.Application {
|
||||||
app := iris.New()
|
app := iris.New()
|
||||||
app.Logger().SetLevel("debug")
|
|
||||||
|
|
||||||
registerErrors(app)
|
registerErrors(app)
|
||||||
registerGamesRoutes(app)
|
registerGamesRoutes(app)
|
||||||
|
|
|
@ -386,18 +386,8 @@ func (r *Route) Trace(w io.Writer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
path := r.Tmpl().Src
|
path := r.Tmpl().Src
|
||||||
|
if path == "" {
|
||||||
if subdomain := r.Subdomain; subdomain != "" {
|
path = "/"
|
||||||
if path == "" {
|
|
||||||
path = "/"
|
|
||||||
}
|
|
||||||
|
|
||||||
if subdomain == "*." { // wildcard.
|
|
||||||
subdomain = "subdomain"
|
|
||||||
}
|
|
||||||
|
|
||||||
r.Description = fmt.Sprintf("%s", subdomain)
|
|
||||||
// path = fmt.Sprintf("%s %s", r.Subdomain, path)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @method: @path
|
// @method: @path
|
||||||
|
@ -408,8 +398,22 @@ func (r *Route) Trace(w io.Writer) {
|
||||||
|
|
||||||
// (@description)
|
// (@description)
|
||||||
description := r.Description
|
description := r.Description
|
||||||
if description == "" && r.Method == MethodNone {
|
if description == "" {
|
||||||
description = "offline"
|
if r.Method == MethodNone {
|
||||||
|
description = "offline"
|
||||||
|
}
|
||||||
|
|
||||||
|
if subdomain := r.Subdomain; subdomain != "" {
|
||||||
|
if subdomain == "*." { // wildcard.
|
||||||
|
subdomain = "subdomain"
|
||||||
|
}
|
||||||
|
|
||||||
|
if description == "offline" {
|
||||||
|
description += ", "
|
||||||
|
}
|
||||||
|
|
||||||
|
description += subdomain
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if description != "" {
|
if description != "" {
|
||||||
|
|
4
go.mod
4
go.mod
|
@ -20,9 +20,9 @@ require (
|
||||||
github.com/iris-contrib/pongo2 v0.0.1
|
github.com/iris-contrib/pongo2 v0.0.1
|
||||||
github.com/iris-contrib/schema v0.0.1
|
github.com/iris-contrib/schema v0.0.1
|
||||||
github.com/json-iterator/go v1.1.9
|
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/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/kataras/sitemap v0.0.5
|
||||||
github.com/klauspost/compress v1.10.5
|
github.com/klauspost/compress v1.10.5
|
||||||
github.com/mediocregopher/radix/v3 v3.5.0
|
github.com/mediocregopher/radix/v3 v3.5.0
|
||||||
|
|
143
iris.go
143
iris.go
|
@ -728,88 +728,93 @@ func (app *Application) Shutdown(ctx stdContext.Context) error {
|
||||||
// app.Logger().Errorf("%s: %s", typ, err)
|
// app.Logger().Errorf("%s: %s", typ, err)
|
||||||
// })
|
// })
|
||||||
func (app *Application) Build() error {
|
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 := errgroup.New("Application Builder")
|
||||||
|
rp.Err(app.APIBuilder.GetReporter())
|
||||||
|
|
||||||
if !app.builded {
|
if app.defaultMode { // the app.I18n and app.View will be not available until Build.
|
||||||
app.builded = true
|
if !app.I18n.Loaded() {
|
||||||
rp.Err(app.APIBuilder.GetReporter())
|
for _, s := range []string{"./locales/*/*", "./locales/*", "./translations"} {
|
||||||
|
if _, err := os.Stat(s); os.IsNotExist(err) {
|
||||||
if app.defaultMode { // the app.I18n and app.View will be not available until Build.
|
continue
|
||||||
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.view.Len() == 0 {
|
if err := app.I18n.Load(s); err != nil {
|
||||||
for _, s := range []string{"./views", "./templates", "./web/views"} {
|
continue
|
||||||
if _, err := os.Stat(s); os.IsNotExist(err) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
app.RegisterView(HTML(s, ".html"))
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
app.I18n.SetDefault("en-US")
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if app.I18n.Loaded() {
|
if app.view.Len() == 0 {
|
||||||
// {{ tr "lang" "key" arg1 arg2 }}
|
for _, s := range []string{"./views", "./templates", "./web/views"} {
|
||||||
app.view.AddFunc("tr", app.I18n.Tr)
|
if _, err := os.Stat(s); os.IsNotExist(err) {
|
||||||
app.Router.WrapRouter(app.I18n.Wrapper())
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if n := app.view.Len(); n > 0 {
|
app.RegisterView(HTML(s, ".html"))
|
||||||
tr := "engines"
|
break
|
||||||
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 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)
|
return errgroup.Check(rp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user