options.go 964 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package param
  2. import (
  3. "fmt"
  4. )
  5. // MethodParamOption defines a func which apply options on a MethodParam
  6. type MethodParamOption func(*MethodParam)
  7. // IsRequired indicates that this param is required and can not be omitted from the http request
  8. var IsRequired MethodParamOption = func(p *MethodParam) {
  9. p.required = true
  10. }
  11. // InHeader indicates that this param is passed via an http header
  12. var InHeader MethodParamOption = func(p *MethodParam) {
  13. p.in = header
  14. }
  15. // InPath indicates that this param is part of the URL path
  16. var InPath MethodParamOption = func(p *MethodParam) {
  17. p.in = path
  18. }
  19. // InBody indicates that this param is passed as an http request body
  20. var InBody MethodParamOption = func(p *MethodParam) {
  21. p.in = body
  22. }
  23. // Default provides a default value for the http param
  24. func Default(defaultValue interface{}) MethodParamOption {
  25. return func(p *MethodParam) {
  26. if defaultValue != nil {
  27. p.defaultValue = fmt.Sprint(defaultValue)
  28. }
  29. }
  30. }