MCPcopy Index your code
hub / github.com/oapi-codegen/oapi-codegen / HandlerWithOptions

Function HandlerWithOptions

examples/overlay/api/ping.gen.go:151–171  ·  view source on GitHub ↗

HandlerWithOptions creates http.Handler with additional options

(si ServerInterface, options GorillaServerOptions)

Source from the content-addressed store, hash-verified

149
150// HandlerWithOptions creates http.Handler with additional options
151func HandlerWithOptions(si ServerInterface, options GorillaServerOptions) http.Handler {
152 r := options.BaseRouter
153
154 if r == nil {
155 r = mux.NewRouter()
156 }
157 if options.ErrorHandlerFunc == nil {
158 options.ErrorHandlerFunc = func(w http.ResponseWriter, r *http.Request, err error) {
159 http.Error(w, err.Error(), http.StatusBadRequest)
160 }
161 }
162 wrapper := ServerInterfaceWrapper{
163 Handler: si,
164 HandlerMiddlewares: options.Middlewares,
165 ErrorHandlerFunc: options.ErrorHandlerFunc,
166 }
167
168 r.HandleFunc(options.BaseURL+"/ping", wrapper.GetPing).Methods(http.MethodGet)
169
170 return r
171}
172
173// Base64 encoded, compressed with deflate, json marshaled OpenAPI spec.
174// Stored as a slice of fixed-width chunks rather than one concatenated

Callers 3

HandlerFunction · 0.70
HandlerFromMuxFunction · 0.70

Calls 2

HandleFuncMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected