github.com/astaxie/beego@v1.12.3/context/param/options.go (about)

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