1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-25 21:01:31 +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 { func getParamValue(param *MethodParam, ctx *beecontext.Context) string {
switch param.location { switch param.in {
case body: case body:
return string(ctx.Input.RequestBody) return string(ctx.Input.RequestBody)
case header: case header:

View File

@ -8,15 +8,15 @@ import (
//MethodParam keeps param information to be auto passed to controller methods //MethodParam keeps param information to be auto passed to controller methods
type MethodParam struct { type MethodParam struct {
name string name string
location paramLocation in paramType
required bool required bool
defaultValue string defaultValue string
} }
type paramLocation byte type paramType byte
const ( const (
param paramLocation = iota param paramType = iota
path path
body body
header header
@ -49,7 +49,7 @@ func (mp *MethodParam) String() string {
if mp.required { if mp.required {
options = append(options, "param.IsRequired") options = append(options, "param.IsRequired")
} }
switch mp.location { switch mp.in {
case path: case path:
options = append(options, "param.InPath") options = append(options, "param.InPath")
case body: 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 // InHeader indicates that this param is passed via an http header
var InHeader MethodParamOption = func(p *MethodParam) { var InHeader MethodParamOption = func(p *MethodParam) {
p.location = header p.in = header
} }
// InPath indicates that this param is part of the URL path // InPath indicates that this param is part of the URL path
var InPath MethodParamOption = func(p *MethodParam) { var InPath MethodParamOption = func(p *MethodParam) {
p.location = path p.in = path
} }
// InBody indicates that this param is passed as an http request body // InBody indicates that this param is passed as an http request body
var InBody MethodParamOption = func(p *MethodParam) { var InBody MethodParamOption = func(p *MethodParam) {
p.location = body p.in = body
} }
// Default provides a default value for the http param // 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 if t.Elem().Kind() == reflect.Uint8 { //treat []byte as string
return stringParser{} return stringParser{}
} }
if param.location == body { if param.in == body {
return jsonParser{} return jsonParser{}
} }
elemParser := getParser(param, t.Elem()) 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) checkParser(testDefinition{`1,2`, []int{1, 2}, sliceParser(intParser{})}, t)
//slice in body is parsed as json //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 //pointers
var someInt = 1 var someInt = 1