MCPcopy Create free account
hub / github.com/kataras/iris / Build

Method Build

iris.go:680–801  ·  view source on GitHub ↗

Build sets up, once, the framework. It builds the default router with its default macros and the template functions that are very-closed to iris. If error occurred while building the Application, the returns type of error will be an *errgroup.Group which let the callers to inspect the errors and ca

()

Source from the content-addressed store, hash-verified

678// app.Logger().Errorf("%s: %s", typ, err)
679// })
680func (app *Application) Build() error {
681 if app.builded {
682 return nil
683 }
684
685 if cb := app.OnBuild; cb != nil {
686 if err := cb(); err != nil {
687 return fmt.Errorf("build: %w", err)
688 }
689 }
690
691 // start := time.Now()
692 app.builded = true // even if fails.
693
694 // check if a prior app.Logger().SetLevel called and if not
695 // then set the defined configuration's log level.
696 if app.logger.Level == golog.InfoLevel /* the default level */ {
697 app.logger.SetLevel(app.config.LogLevel)
698 }
699
700 if app.defaultMode { // the app.I18n and app.View will be not available until Build.
701 if !app.I18n.Loaded() {
702 for _, s := range []string{"./locales/*/*", "./locales/*", "./translations"} {
703 if _, err := os.Stat(s); err != nil {
704 continue
705 }
706
707 if err := app.I18n.Load(s); err != nil {
708 continue
709 }
710
711 app.I18n.SetDefault("en-US")
712 break
713 }
714 }
715
716 if !app.view.Registered() {
717 for _, s := range []string{"./views", "./templates", "./web/views"} {
718 if _, err := os.Stat(s); err != nil {
719 continue
720 }
721
722 app.RegisterView(HTML(s, ".html"))
723 break
724 }
725 }
726 }
727
728 if app.I18n.Loaded() {
729 // {{ tr "lang" "key" arg1 arg2 }}
730 app.view.AddFunc("tr", app.I18n.Tr)
731 app.Router.PrependRouterWrapper(app.I18n.Wrapper())
732 }
733
734 if app.view.Registered() {
735 app.logger.Debugf("Application: view engine %q is registered", app.view.Name())
736 // view engine
737 // here is where we declare the closed-relative framework functions.

Callers 1

RunMethod · 0.95

Calls 15

RegisterViewMethod · 0.95
ConfigureHostMethod · 0.95
NewRoutePathReverserFunction · 0.92
NewDefaultHandlerFunction · 0.92
HTMLFunction · 0.85
injectLiveReloadFunction · 0.85
ErrorfMethod · 0.80
LoadedMethod · 0.80
RegisteredMethod · 0.80
PrependRouterWrapperMethod · 0.80
DowngradedMethod · 0.80
BuildRouterMethod · 0.80

Tested by

no test coverage detected