1
0
mirror of https://github.com/astaxie/beego.git synced 2024-12-22 18:00:49 +00:00

location=>paramType

This commit is contained in:
eyalpost 2017-05-12 09:28:46 +03:00
parent b6a35a8944
commit 0ac2e47162
5 changed files with 10 additions and 10 deletions

View File

@ -38,7 +38,7 @@ func convertParam(param *MethodParam, paramType reflect.Type, ctx *beecontext.Co
}
func getParamValue(param *MethodParam, ctx *beecontext.Context) string {
switch param.location {
switch param.in {
case body:
return string(ctx.Input.RequestBody)
case header:

View File

@ -8,15 +8,15 @@ import (
//MethodParam keeps param information to be auto passed to controller methods
type MethodParam struct {
name string
location paramLocation
in paramType
required bool
defaultValue string
}
type paramLocation byte
type paramType byte
const (
param paramLocation = iota
param paramType = iota
path
body
header
@ -49,7 +49,7 @@ func (mp *MethodParam) String() string {
if mp.required {
options = append(options, "param.IsRequired")
}
switch mp.location {
switch mp.in {
case path:
options = append(options, "param.InPath")
case body:

View File

@ -14,17 +14,17 @@ var IsRequired MethodParamOption = func(p *MethodParam) {
// InHeader indicates that this param is passed via an http header
var InHeader MethodParamOption = func(p *MethodParam) {
p.location = header
p.in = header
}
// InPath indicates that this param is part of the URL path
var InPath MethodParamOption = func(p *MethodParam) {
p.location = path
p.in = path
}
// InBody indicates that this param is passed as an http request body
var InBody MethodParamOption = func(p *MethodParam) {
p.location = body
p.in = body
}
// Default provides a default value for the http param

View File

@ -21,7 +21,7 @@ func getParser(param *MethodParam, t reflect.Type) paramParser {
if t.Elem().Kind() == reflect.Uint8 { //treat []byte as string
return stringParser{}
}
if param.location == body {
if param.in == body {
return jsonParser{}
}
elemParser := getParser(param, t.Elem())

View File

@ -43,7 +43,7 @@ func Test_Parsers(t *testing.T) {
checkParser(testDefinition{`1,2`, []int{1, 2}, sliceParser(intParser{})}, t)
//slice in body is parsed as json
checkParser(testDefinition{`["a","b"]`, []string{"a", "b"}, jsonParser{}}, t, MethodParam{location: body})
checkParser(testDefinition{`["a","b"]`, []string{"a", "b"}, jsonParser{}}, t, MethodParam{in: body})
//pointers
var someInt = 1