github.com/Bio-core/jtree@v0.0.0-20190705165106-1d7a7e7d6272/restapi/operations/jtree_metadata_api.go (about) 1 package operations 2 3 // This file was generated by the swagger tool. 4 // Editing this file might prove futile when you re-run the swagger generate command 5 6 import ( 7 "fmt" 8 "net/http" 9 "strings" 10 11 errors "github.com/go-openapi/errors" 12 loads "github.com/go-openapi/loads" 13 runtime "github.com/go-openapi/runtime" 14 middleware "github.com/go-openapi/runtime/middleware" 15 security "github.com/go-openapi/runtime/security" 16 spec "github.com/go-openapi/spec" 17 strfmt "github.com/go-openapi/strfmt" 18 "github.com/go-openapi/swag" 19 ) 20 21 // NewJtreeMetadataAPI creates a new JtreeMetadata instance 22 func NewJtreeMetadataAPI(spec *loads.Document) *JtreeMetadataAPI { 23 return &JtreeMetadataAPI{ 24 handlers: make(map[string]map[string]http.Handler), 25 formats: strfmt.Default, 26 defaultConsumes: "application/json", 27 defaultProduces: "application/json", 28 customConsumers: make(map[string]runtime.Consumer), 29 customProducers: make(map[string]runtime.Producer), 30 ServerShutdown: func() {}, 31 spec: spec, 32 ServeError: errors.ServeError, 33 BasicAuthenticator: security.BasicAuth, 34 APIKeyAuthenticator: security.APIKeyAuth, 35 BearerAuthenticator: security.BearerAuth, 36 JSONConsumer: runtime.JSONConsumer(), 37 MultipartformConsumer: runtime.DiscardConsumer, 38 JSONProducer: runtime.JSONProducer(), 39 PostUploadHandler: PostUploadHandlerFunc(func(params PostUploadParams) middleware.Responder { 40 return middleware.NotImplemented("operation PostUpload has not yet been implemented") 41 }), 42 AddExperimentHandler: AddExperimentHandlerFunc(func(params AddExperimentParams) middleware.Responder { 43 return middleware.NotImplemented("operation AddExperiment has not yet been implemented") 44 }), 45 AddPatientHandler: AddPatientHandlerFunc(func(params AddPatientParams) middleware.Responder { 46 return middleware.NotImplemented("operation AddPatient has not yet been implemented") 47 }), 48 AddResultHandler: AddResultHandlerFunc(func(params AddResultParams) middleware.Responder { 49 return middleware.NotImplemented("operation AddResult has not yet been implemented") 50 }), 51 AddResultdetailsHandler: AddResultdetailsHandlerFunc(func(params AddResultdetailsParams) middleware.Responder { 52 return middleware.NotImplemented("operation AddResultdetails has not yet been implemented") 53 }), 54 AddSampleHandler: AddSampleHandlerFunc(func(params AddSampleParams) middleware.Responder { 55 return middleware.NotImplemented("operation AddSample has not yet been implemented") 56 }), 57 GetSampleColumnsHandler: GetSampleColumnsHandlerFunc(func(params GetSampleColumnsParams) middleware.Responder { 58 return middleware.NotImplemented("operation GetSampleColumns has not yet been implemented") 59 }), 60 GetSamplesByQueryHandler: GetSamplesByQueryHandlerFunc(func(params GetSamplesByQueryParams) middleware.Responder { 61 return middleware.NotImplemented("operation GetSamplesByQuery has not yet been implemented") 62 }), 63 GetSearchableHandler: GetSearchableHandlerFunc(func(params GetSearchableParams) middleware.Responder { 64 return middleware.NotImplemented("operation GetSearchable has not yet been implemented") 65 }), 66 GetUneditableHandler: GetUneditableHandlerFunc(func(params GetUneditableParams) middleware.Responder { 67 return middleware.NotImplemented("operation GetUneditable has not yet been implemented") 68 }), 69 LogoutHandler: LogoutHandlerFunc(func(params LogoutParams) middleware.Responder { 70 return middleware.NotImplemented("operation Logout has not yet been implemented") 71 }), 72 } 73 } 74 75 /*JtreeMetadataAPI Metadata API */ 76 type JtreeMetadataAPI struct { 77 spec *loads.Document 78 context *middleware.Context 79 handlers map[string]map[string]http.Handler 80 formats strfmt.Registry 81 customConsumers map[string]runtime.Consumer 82 customProducers map[string]runtime.Producer 83 defaultConsumes string 84 defaultProduces string 85 Middleware func(middleware.Builder) http.Handler 86 87 // BasicAuthenticator generates a runtime.Authenticator from the supplied basic auth function. 88 // It has a default implemention in the security package, however you can replace it for your particular usage. 89 BasicAuthenticator func(security.UserPassAuthentication) runtime.Authenticator 90 // APIKeyAuthenticator generates a runtime.Authenticator from the supplied token auth function. 91 // It has a default implemention in the security package, however you can replace it for your particular usage. 92 APIKeyAuthenticator func(string, string, security.TokenAuthentication) runtime.Authenticator 93 // BearerAuthenticator generates a runtime.Authenticator from the supplied bearer token auth function. 94 // It has a default implemention in the security package, however you can replace it for your particular usage. 95 BearerAuthenticator func(string, security.ScopedTokenAuthentication) runtime.Authenticator 96 97 // JSONConsumer registers a consumer for a "application/json" mime type 98 JSONConsumer runtime.Consumer 99 // MultipartformConsumer registers a consumer for a "multipart/form-data" mime type 100 MultipartformConsumer runtime.Consumer 101 102 // JSONProducer registers a producer for a "application/json" mime type 103 JSONProducer runtime.Producer 104 // PostUploadHandler sets the operation handler for the post upload operation 105 PostUploadHandler PostUploadHandler 106 // AddExperimentHandler sets the operation handler for the add experiment operation 107 AddExperimentHandler AddExperimentHandler 108 // AddPatientHandler sets the operation handler for the add patient operation 109 AddPatientHandler AddPatientHandler 110 // AddResultHandler sets the operation handler for the add result operation 111 AddResultHandler AddResultHandler 112 // AddResultdetailsHandler sets the operation handler for the add resultdetails operation 113 AddResultdetailsHandler AddResultdetailsHandler 114 // AddSampleHandler sets the operation handler for the add sample operation 115 AddSampleHandler AddSampleHandler 116 // GetSampleColumnsHandler sets the operation handler for the get sample columns operation 117 GetSampleColumnsHandler GetSampleColumnsHandler 118 // GetSamplesByQueryHandler sets the operation handler for the get samples by query operation 119 GetSamplesByQueryHandler GetSamplesByQueryHandler 120 // GetSearchableHandler sets the operation handler for the get searchable operation 121 GetSearchableHandler GetSearchableHandler 122 // GetUneditableHandler sets the operation handler for the get uneditable operation 123 GetUneditableHandler GetUneditableHandler 124 // LogoutHandler sets the operation handler for the logout operation 125 LogoutHandler LogoutHandler 126 127 // ServeError is called when an error is received, there is a default handler 128 // but you can set your own with this 129 ServeError func(http.ResponseWriter, *http.Request, error) 130 131 // ServerShutdown is called when the HTTP(S) server is shut down and done 132 // handling all active connections and does not accept connections any more 133 ServerShutdown func() 134 135 // Custom command line argument groups with their descriptions 136 CommandLineOptionsGroups []swag.CommandLineOptionsGroup 137 138 // User defined logger function. 139 Logger func(string, ...interface{}) 140 } 141 142 // SetDefaultProduces sets the default produces media type 143 func (o *JtreeMetadataAPI) SetDefaultProduces(mediaType string) { 144 o.defaultProduces = mediaType 145 } 146 147 // SetDefaultConsumes returns the default consumes media type 148 func (o *JtreeMetadataAPI) SetDefaultConsumes(mediaType string) { 149 o.defaultConsumes = mediaType 150 } 151 152 // SetSpec sets a spec that will be served for the clients. 153 func (o *JtreeMetadataAPI) SetSpec(spec *loads.Document) { 154 o.spec = spec 155 } 156 157 // DefaultProduces returns the default produces media type 158 func (o *JtreeMetadataAPI) DefaultProduces() string { 159 return o.defaultProduces 160 } 161 162 // DefaultConsumes returns the default consumes media type 163 func (o *JtreeMetadataAPI) DefaultConsumes() string { 164 return o.defaultConsumes 165 } 166 167 // Formats returns the registered string formats 168 func (o *JtreeMetadataAPI) Formats() strfmt.Registry { 169 return o.formats 170 } 171 172 // RegisterFormat registers a custom format validator 173 func (o *JtreeMetadataAPI) RegisterFormat(name string, format strfmt.Format, validator strfmt.Validator) { 174 o.formats.Add(name, format, validator) 175 } 176 177 // Validate validates the registrations in the JtreeMetadataAPI 178 func (o *JtreeMetadataAPI) Validate() error { 179 var unregistered []string 180 181 if o.JSONConsumer == nil { 182 unregistered = append(unregistered, "JSONConsumer") 183 } 184 185 if o.JSONProducer == nil { 186 unregistered = append(unregistered, "JSONProducer") 187 } 188 if o.PostUploadHandler == nil { 189 unregistered = append(unregistered, "PostUploadHandler") 190 } 191 192 if o.AddExperimentHandler == nil { 193 unregistered = append(unregistered, "AddExperimentHandler") 194 } 195 196 if o.AddPatientHandler == nil { 197 unregistered = append(unregistered, "AddPatientHandler") 198 } 199 200 if o.AddResultHandler == nil { 201 unregistered = append(unregistered, "AddResultHandler") 202 } 203 204 if o.AddResultdetailsHandler == nil { 205 unregistered = append(unregistered, "AddResultdetailsHandler") 206 } 207 208 if o.AddSampleHandler == nil { 209 unregistered = append(unregistered, "AddSampleHandler") 210 } 211 212 if o.GetSampleColumnsHandler == nil { 213 unregistered = append(unregistered, "GetSampleColumnsHandler") 214 } 215 216 if o.GetSamplesByQueryHandler == nil { 217 unregistered = append(unregistered, "GetSamplesByQueryHandler") 218 } 219 220 if o.GetSearchableHandler == nil { 221 unregistered = append(unregistered, "GetSearchableHandler") 222 } 223 224 if o.GetUneditableHandler == nil { 225 unregistered = append(unregistered, "GetUneditableHandler") 226 } 227 228 if o.LogoutHandler == nil { 229 unregistered = append(unregistered, "LogoutHandler") 230 } 231 232 if len(unregistered) > 0 { 233 return fmt.Errorf("missing registration: %s", strings.Join(unregistered, ", ")) 234 } 235 236 return nil 237 } 238 239 // ServeErrorFor gets a error handler for a given operation id 240 func (o *JtreeMetadataAPI) ServeErrorFor(operationID string) func(http.ResponseWriter, *http.Request, error) { 241 return o.ServeError 242 } 243 244 // AuthenticatorsFor gets the authenticators for the specified security schemes 245 func (o *JtreeMetadataAPI) AuthenticatorsFor(schemes map[string]spec.SecurityScheme) map[string]runtime.Authenticator { 246 247 return nil 248 249 } 250 251 // Authorizer returns the registered authorizer 252 func (o *JtreeMetadataAPI) Authorizer() runtime.Authorizer { 253 254 return nil 255 256 } 257 258 // ConsumersFor gets the consumers for the specified media types 259 func (o *JtreeMetadataAPI) ConsumersFor(mediaTypes []string) map[string]runtime.Consumer { 260 261 result := make(map[string]runtime.Consumer) 262 for _, mt := range mediaTypes { 263 switch mt { 264 265 case "application/json": 266 result["application/json"] = o.JSONConsumer 267 case "multipart/form-data": 268 result["multipart/form-data"] = o.MultipartformConsumer 269 270 } 271 272 if c, ok := o.customConsumers[mt]; ok { 273 result[mt] = c 274 } 275 } 276 return result 277 278 } 279 280 // ProducersFor gets the producers for the specified media types 281 func (o *JtreeMetadataAPI) ProducersFor(mediaTypes []string) map[string]runtime.Producer { 282 283 result := make(map[string]runtime.Producer) 284 for _, mt := range mediaTypes { 285 switch mt { 286 287 case "application/json": 288 result["application/json"] = o.JSONProducer 289 290 } 291 292 if p, ok := o.customProducers[mt]; ok { 293 result[mt] = p 294 } 295 } 296 return result 297 298 } 299 300 // HandlerFor gets a http.Handler for the provided operation method and path 301 func (o *JtreeMetadataAPI) HandlerFor(method, path string) (http.Handler, bool) { 302 if o.handlers == nil { 303 return nil, false 304 } 305 um := strings.ToUpper(method) 306 if _, ok := o.handlers[um]; !ok { 307 return nil, false 308 } 309 if path == "/" { 310 path = "" 311 } 312 h, ok := o.handlers[um][path] 313 return h, ok 314 } 315 316 // Context returns the middleware context for the jtree metadata API 317 func (o *JtreeMetadataAPI) Context() *middleware.Context { 318 if o.context == nil { 319 o.context = middleware.NewRoutableContext(o.spec, o, nil) 320 } 321 322 return o.context 323 } 324 325 func (o *JtreeMetadataAPI) initHandlerCache() { 326 o.Context() // don't care about the result, just that the initialization happened 327 328 if o.handlers == nil { 329 o.handlers = make(map[string]map[string]http.Handler) 330 } 331 332 if o.handlers["POST"] == nil { 333 o.handlers["POST"] = make(map[string]http.Handler) 334 } 335 o.handlers["POST"]["/upload"] = NewPostUpload(o.context, o.PostUploadHandler) 336 337 if o.handlers["POST"] == nil { 338 o.handlers["POST"] = make(map[string]http.Handler) 339 } 340 o.handlers["POST"]["/experiment"] = NewAddExperiment(o.context, o.AddExperimentHandler) 341 342 if o.handlers["POST"] == nil { 343 o.handlers["POST"] = make(map[string]http.Handler) 344 } 345 o.handlers["POST"]["/patient"] = NewAddPatient(o.context, o.AddPatientHandler) 346 347 if o.handlers["POST"] == nil { 348 o.handlers["POST"] = make(map[string]http.Handler) 349 } 350 o.handlers["POST"]["/result"] = NewAddResult(o.context, o.AddResultHandler) 351 352 if o.handlers["POST"] == nil { 353 o.handlers["POST"] = make(map[string]http.Handler) 354 } 355 o.handlers["POST"]["/resultdetails"] = NewAddResultdetails(o.context, o.AddResultdetailsHandler) 356 357 if o.handlers["POST"] == nil { 358 o.handlers["POST"] = make(map[string]http.Handler) 359 } 360 o.handlers["POST"]["/sample"] = NewAddSample(o.context, o.AddSampleHandler) 361 362 if o.handlers["GET"] == nil { 363 o.handlers["GET"] = make(map[string]http.Handler) 364 } 365 o.handlers["GET"]["/columns"] = NewGetSampleColumns(o.context, o.GetSampleColumnsHandler) 366 367 if o.handlers["POST"] == nil { 368 o.handlers["POST"] = make(map[string]http.Handler) 369 } 370 o.handlers["POST"]["/query"] = NewGetSamplesByQuery(o.context, o.GetSamplesByQueryHandler) 371 372 if o.handlers["GET"] == nil { 373 o.handlers["GET"] = make(map[string]http.Handler) 374 } 375 o.handlers["GET"]["/searchable"] = NewGetSearchable(o.context, o.GetSearchableHandler) 376 377 if o.handlers["GET"] == nil { 378 o.handlers["GET"] = make(map[string]http.Handler) 379 } 380 o.handlers["GET"]["/uneditable"] = NewGetUneditable(o.context, o.GetUneditableHandler) 381 382 if o.handlers["GET"] == nil { 383 o.handlers["GET"] = make(map[string]http.Handler) 384 } 385 o.handlers["GET"]["/logout"] = NewLogout(o.context, o.LogoutHandler) 386 387 } 388 389 // Serve creates a http handler to serve the API over HTTP 390 // can be used directly in http.ListenAndServe(":8000", api.Serve(nil)) 391 func (o *JtreeMetadataAPI) Serve(builder middleware.Builder) http.Handler { 392 o.Init() 393 394 if o.Middleware != nil { 395 return o.Middleware(builder) 396 } 397 return o.context.APIHandler(builder) 398 } 399 400 // Init allows you to just initialize the handler cache, you can then recompose the middleware as you see fit 401 func (o *JtreeMetadataAPI) Init() { 402 if len(o.handlers) == 0 { 403 o.initHandlerCache() 404 } 405 } 406 407 // RegisterConsumer allows you to add (or override) a consumer for a media type. 408 func (o *JtreeMetadataAPI) RegisterConsumer(mediaType string, consumer runtime.Consumer) { 409 o.customConsumers[mediaType] = consumer 410 } 411 412 // RegisterProducer allows you to add (or override) a producer for a media type. 413 func (o *JtreeMetadataAPI) RegisterProducer(mediaType string, producer runtime.Producer) { 414 o.customProducers[mediaType] = producer 415 }