2017-04-21 12:26:41 +00:00
|
|
|
package param
|
|
|
|
|
2017-04-22 22:33:50 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2017-04-30 16:28:26 +00:00
|
|
|
// MethodParamOption defines a func which apply options on a MethodParam
|
2017-04-25 13:00:49 +00:00
|
|
|
type MethodParamOption func(*MethodParam)
|
|
|
|
|
2017-09-07 11:01:34 +00:00
|
|
|
// IsRequired indicates that this param is required and can not be omitted from the http request
|
2017-04-22 22:33:50 +00:00
|
|
|
var IsRequired MethodParamOption = func(p *MethodParam) {
|
|
|
|
p.required = true
|
|
|
|
}
|
|
|
|
|
2017-04-30 16:28:26 +00:00
|
|
|
// InHeader indicates that this param is passed via an http header
|
2017-04-21 12:26:41 +00:00
|
|
|
var InHeader MethodParamOption = func(p *MethodParam) {
|
2017-05-12 06:28:46 +00:00
|
|
|
p.in = header
|
2017-04-21 12:26:41 +00:00
|
|
|
}
|
|
|
|
|
2017-04-30 16:28:26 +00:00
|
|
|
// InPath indicates that this param is part of the URL path
|
2017-04-25 13:00:49 +00:00
|
|
|
var InPath MethodParamOption = func(p *MethodParam) {
|
2017-05-12 06:28:46 +00:00
|
|
|
p.in = path
|
2017-04-25 13:00:49 +00:00
|
|
|
}
|
|
|
|
|
2017-04-30 16:28:26 +00:00
|
|
|
// InBody indicates that this param is passed as an http request body
|
2017-04-22 22:33:50 +00:00
|
|
|
var InBody MethodParamOption = func(p *MethodParam) {
|
2017-05-12 06:28:46 +00:00
|
|
|
p.in = body
|
2017-04-21 12:26:41 +00:00
|
|
|
}
|
|
|
|
|
2017-04-30 16:28:26 +00:00
|
|
|
// Default provides a default value for the http param
|
2017-05-11 14:58:25 +00:00
|
|
|
func Default(defaultValue interface{}) MethodParamOption {
|
2017-04-21 12:26:41 +00:00
|
|
|
return func(p *MethodParam) {
|
2017-05-11 14:58:25 +00:00
|
|
|
if defaultValue != nil {
|
|
|
|
p.defaultValue = fmt.Sprint(defaultValue)
|
2017-04-22 22:33:50 +00:00
|
|
|
}
|
2017-04-21 12:26:41 +00:00
|
|
|
}
|
|
|
|
}
|