本站源代码
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

104 linhas
3.6KB

  1. // Copyright 2015 go-swagger maintainers
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package runtime
  15. import (
  16. "io"
  17. "net/http"
  18. "github.com/go-openapi/strfmt"
  19. )
  20. // OperationHandlerFunc an adapter for a function to the OperationHandler interface
  21. type OperationHandlerFunc func(interface{}) (interface{}, error)
  22. // Handle implements the operation handler interface
  23. func (s OperationHandlerFunc) Handle(data interface{}) (interface{}, error) {
  24. return s(data)
  25. }
  26. // OperationHandler a handler for a swagger operation
  27. type OperationHandler interface {
  28. Handle(interface{}) (interface{}, error)
  29. }
  30. // ConsumerFunc represents a function that can be used as a consumer
  31. type ConsumerFunc func(io.Reader, interface{}) error
  32. // Consume consumes the reader into the data parameter
  33. func (fn ConsumerFunc) Consume(reader io.Reader, data interface{}) error {
  34. return fn(reader, data)
  35. }
  36. // Consumer implementations know how to bind the values on the provided interface to
  37. // data provided by the request body
  38. type Consumer interface {
  39. // Consume performs the binding of request values
  40. Consume(io.Reader, interface{}) error
  41. }
  42. // ProducerFunc represents a function that can be used as a producer
  43. type ProducerFunc func(io.Writer, interface{}) error
  44. // Produce produces the response for the provided data
  45. func (f ProducerFunc) Produce(writer io.Writer, data interface{}) error {
  46. return f(writer, data)
  47. }
  48. // Producer implementations know how to turn the provided interface into a valid
  49. // HTTP response
  50. type Producer interface {
  51. // Produce writes to the http response
  52. Produce(io.Writer, interface{}) error
  53. }
  54. // AuthenticatorFunc turns a function into an authenticator
  55. type AuthenticatorFunc func(interface{}) (bool, interface{}, error)
  56. // Authenticate authenticates the request with the provided data
  57. func (f AuthenticatorFunc) Authenticate(params interface{}) (bool, interface{}, error) {
  58. return f(params)
  59. }
  60. // Authenticator represents an authentication strategy
  61. // implementations of Authenticator know how to authenticate the
  62. // request data and translate that into a valid principal object or an error
  63. type Authenticator interface {
  64. Authenticate(interface{}) (bool, interface{}, error)
  65. }
  66. // AuthorizerFunc turns a function into an authorizer
  67. type AuthorizerFunc func(*http.Request, interface{}) error
  68. // Authorize authorizes the processing of the request for the principal
  69. func (f AuthorizerFunc) Authorize(r *http.Request, principal interface{}) error {
  70. return f(r, principal)
  71. }
  72. // Authorizer represents an authorization strategy
  73. // implementations of Authorizer know how to authorize the principal object
  74. // using the request data and returns error if unauthorized
  75. type Authorizer interface {
  76. Authorize(*http.Request, interface{}) error
  77. }
  78. // Validatable types implementing this interface allow customizing their validation
  79. // this will be used instead of the reflective validation based on the spec document.
  80. // the implementations are assumed to have been generated by the swagger tool so they should
  81. // contain all the validations obtained from the spec
  82. type Validatable interface {
  83. Validate(strfmt.Registry) error
  84. }
上海开阖软件有限公司 沪ICP备12045867号-1