1
0
mirror of https://github.com/astaxie/beego.git synced 2025-06-11 14:40:39 +00:00

golint fixes

This commit is contained in:
Eyal Post
2017-04-30 19:28:26 +03:00
parent cfb2f68dd6
commit 1b8f05cef1
6 changed files with 27 additions and 13 deletions

View File

@ -8,6 +8,7 @@ import (
"github.com/astaxie/beego/logs"
)
// ConvertParams converts http method params to values that will be passed to the method controller as arguments
func ConvertParams(methodParams []*MethodParam, methodType reflect.Type, ctx *beecontext.Context) (result []reflect.Value) {
result = make([]reflect.Value, 0, len(methodParams))
for i := 0; i < len(methodParams); i++ {
@ -55,15 +56,14 @@ func getParamValue(param *MethodParam, ctx *beecontext.Context) string {
func parseValue(param *MethodParam, paramValue string, paramType reflect.Type) (result reflect.Value, err error) {
if paramValue == "" {
return reflect.Zero(paramType), nil
} else {
parser := getParser(param, paramType)
value, err := parser.parse(paramValue, paramType)
if err != nil {
return result, err
}
return safeConvert(reflect.ValueOf(value), paramType)
}
parser := getParser(param, paramType)
value, err := parser.parse(paramValue, paramType)
if err != nil {
return result, err
}
return safeConvert(reflect.ValueOf(value), paramType)
}
func safeConvert(value reflect.Value, t reflect.Type) (result reflect.Value, err error) {

View File

@ -5,7 +5,7 @@ import (
"strings"
)
//Keeps param information to be auto passed to controller methods
//MethodParam keeps param information to be auto passed to controller methods
type MethodParam struct {
name string
location paramLocation
@ -22,6 +22,7 @@ const (
header
)
//New creates a new MethodParam with name and specific options
func New(name string, opts ...MethodParamOption) *MethodParam {
return newParam(name, nil, opts)
}
@ -34,6 +35,7 @@ func newParam(name string, parser paramParser, opts []MethodParamOption) (param
return
}
//Make creates an array of MethodParmas or an empty array
func Make(list ...*MethodParam) []*MethodParam {
if len(list) > 0 {
return list

View File

@ -4,24 +4,30 @@ import (
"fmt"
)
// MethodParamOption defines a func which apply options on a MethodParam
type MethodParamOption func(*MethodParam)
// IsRequired indicates that this param is required and can not be ommited from the http request
var IsRequired MethodParamOption = func(p *MethodParam) {
p.required = true
}
// InHeader indicates that this param is passed via an http header
var InHeader MethodParamOption = func(p *MethodParam) {
p.location = header
}
// InPath indicates that this param is part of the URL path
var InPath MethodParamOption = func(p *MethodParam) {
p.location = path
}
// InBody indicates that this param is passed as an http request body
var InBody MethodParamOption = func(p *MethodParam) {
p.location = body
}
// Default provides a default value for the http param
func Default(defValue interface{}) MethodParamOption {
return func(p *MethodParam) {
if defValue != nil {