MCPcopy Index your code
hub / github.com/kataras/iris / Build

Method Build

iris_guide.go:503–604  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

501}
502
503func (s *step7) Build() *Application {
504 if s.app != nil {
505 return s.app
506 }
507
508 app := New()
509 app.SetContextErrorHandler(errors.DefaultContextErrorHandler)
510 app.Macros().SetErrorHandler(errors.DefaultPathParameterTypeErrorHandler)
511
512 routeFilters := s.step6.step5.routerMiddlewares
513 if !context.HandlerExists(routeFilters, errors.RecoveryHandler) {
514 // If not errors.RecoveryHandler registered, then use the default one.
515 app.UseRouter(recover.New())
516 }
517
518 app.UseRouter(routeFilters...)
519 app.UseRouter(func(ctx Context) {
520 ctx.Header("Server", "Iris")
521 if dev := s.step6.step5.step4.step3.developer; dev != "" {
522 ctx.Header("X-Developer", dev)
523 }
524
525 ctx.Next()
526 })
527
528 if allowOrigin := s.step6.step5.step4.step3.step2.step1.originLine; strings.TrimSpace(allowOrigin) != "" && allowOrigin != "none" {
529 corsMiddleware := cors.New().HandleErrorFunc(errors.FailedPrecondition.Err).AllowOrigin(allowOrigin).Handler()
530 app.UseRouter(corsMiddleware)
531 }
532
533 if s.step6.step5.step4.step3.step2.enableCompression {
534 app.Use(Compression)
535 }
536
537 for _, middleware := range s.step6.step5.middlewares {
538 if middleware == nil {
539 continue
540 }
541
542 app.Use(middleware)
543 }
544
545 if configAsDeps := s.step6.configuratorsAsDeps; len(configAsDeps) > 0 {
546 app.Configure(configAsDeps...)
547 }
548
549 if s.step6.step5.step4.step3.enableHealth {
550 app.Get("/health", modrevision.New(modrevision.Options{
551 ServerName: "Iris Server",
552 Env: s.step6.step5.step4.step3.env,
553 Developer: s.step6.step5.step4.step3.developer,
554 }))
555 }
556
557 if deps := s.step6.deps; len(deps) > 0 {
558 app.EnsureStaticBindings().RegisterDependency(deps...)
559 }
560

Callers 1

RunMethod · 0.95

Calls 15

HandlerExistsFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92
WithoutServerErrorFunction · 0.85
WithRemoteAddrHeaderFunction · 0.85
WithTimeoutFunction · 0.85
NextMethod · 0.80
HandleErrorFuncMethod · 0.80
getPrefixMethod · 0.80
ConfigureHostMethod · 0.80

Tested by

no test coverage detected