HandlerWithOptions creates http.Handler with additional options
(si ServerInterface, options ChiServerOptions)
| 624 | |
| 625 | // HandlerWithOptions creates http.Handler with additional options |
| 626 | func HandlerWithOptions(si ServerInterface, options ChiServerOptions) http.Handler { |
| 627 | r := options.BaseRouter |
| 628 | |
| 629 | if r == nil { |
| 630 | r = chi.NewRouter() |
| 631 | } |
| 632 | if options.ErrorHandlerFunc == nil { |
| 633 | options.ErrorHandlerFunc = func(w http.ResponseWriter, r *http.Request, err error) { |
| 634 | http.Error(w, err.Error(), http.StatusBadRequest) |
| 635 | } |
| 636 | } |
| 637 | wrapper := ServerInterfaceWrapper{ |
| 638 | Handler: si, |
| 639 | HandlerMiddlewares: options.Middlewares, |
| 640 | ErrorHandlerFunc: options.ErrorHandlerFunc, |
| 641 | } |
| 642 | |
| 643 | r.Group(func(r chi.Router) { |
| 644 | r.Get(options.BaseURL+"/every-type-optional", wrapper.GetEveryTypeOptional) |
| 645 | }) |
| 646 | r.Group(func(r chi.Router) { |
| 647 | r.Get(options.BaseURL+"/get-simple", wrapper.GetSimple) |
| 648 | }) |
| 649 | r.Group(func(r chi.Router) { |
| 650 | r.Get(options.BaseURL+"/get-with-args", wrapper.GetWithArgs) |
| 651 | }) |
| 652 | r.Group(func(r chi.Router) { |
| 653 | r.Get(options.BaseURL+"/get-with-references/{global_argument}/{argument}", wrapper.GetWithReferences) |
| 654 | }) |
| 655 | r.Group(func(r chi.Router) { |
| 656 | r.Get(options.BaseURL+"/get-with-type/{content_type}", wrapper.GetWithContentType) |
| 657 | }) |
| 658 | r.Group(func(r chi.Router) { |
| 659 | r.Get(options.BaseURL+"/reserved-keyword", wrapper.GetReservedKeyword) |
| 660 | }) |
| 661 | r.Group(func(r chi.Router) { |
| 662 | r.Post(options.BaseURL+"/resource/{argument}", wrapper.CreateResource) |
| 663 | }) |
| 664 | r.Group(func(r chi.Router) { |
| 665 | r.Post(options.BaseURL+"/resource2/{inline_argument}", wrapper.CreateResource2) |
| 666 | }) |
| 667 | r.Group(func(r chi.Router) { |
| 668 | r.Put(options.BaseURL+"/resource3/{fallthrough}", wrapper.UpdateResource3) |
| 669 | }) |
| 670 | r.Group(func(r chi.Router) { |
| 671 | r.Get(options.BaseURL+"/response-with-reference", wrapper.GetResponseWithReference) |
| 672 | }) |
| 673 | |
| 674 | return r |
| 675 | } |
searching dependent graphs…