Merge pull request #163 from zaquestion/httptransport_cleanup

Rename PBFieldName -> QueryParamName in httptransport to represent its purpose within the package
This commit is contained in:
Zaq? Wiedmann 2017-03-28 12:03:07 -07:00 коммит произвёл GitHub
Родитель 192aa47bb4 5ed3a822a9
Коммит b48ccfdf17
5 изменённых файлов: 19 добавлений и 20 удалений

Просмотреть файл

@ -83,14 +83,14 @@ func NewBinding(i int, meth *svcdef.ServiceMethod) *Binding {
// Methods RequestType
field := param.Field
newField := Field{
Name: field.Name,
PBFieldName: field.PBFieldName,
CamelName: gogen.CamelCase(field.Name),
LowCamelName: LowCamelName(field.Name),
Location: param.Location,
Repeated: field.Type.ArrayType,
GoType: field.Type.Name,
LocalName: fmt.Sprintf("%s%s", gogen.CamelCase(field.Name), gogen.CamelCase(meth.Name)),
Name: field.Name,
QueryParamName: field.PBFieldName,
CamelName: gogen.CamelCase(field.Name),
LowCamelName: LowCamelName(field.Name),
Location: param.Location,
Repeated: field.Type.ArrayType,
GoType: field.Type.Name,
LocalName: fmt.Sprintf("%s%s", gogen.CamelCase(field.Name), gogen.CamelCase(meth.Name)),
}
if field.Type.Message == nil && field.Type.Enum == nil && field.Type.Map == nil {
@ -208,11 +208,11 @@ func (b *Binding) PathSections() []string {
// of a query parameter into it's correct field on the request struct.
func (f *Field) GenQueryUnmarshaler() (string, error) {
queryParamLogic := `
if {{.LocalName}}StrArr, ok := {{.Location}}Params["{{.PBFieldName}}"]; ok {
if {{.LocalName}}StrArr, ok := {{.Location}}Params["{{.QueryParamName}}"]; ok {
{{.LocalName}}Str := {{.LocalName}}StrArr[0]`
pathParamLogic := `
{{.LocalName}}Str := {{.Location}}Params["{{.PBFieldName}}"]`
{{.LocalName}}Str := {{.Location}}Params["{{.QueryParamName}}"]`
genericLogic := `
{{.ConvertFunc}}{{if .ConvertFuncNeedsErrorCheck}}

Просмотреть файл

@ -60,7 +60,7 @@ func TestNewMethod(t *testing.T) {
Fields: []*Field{
&Field{
Name: "A",
PBFieldName: "a",
QueryParamName: "a",
CamelName: "A",
LowCamelName: "a",
LocalName: "ASum",
@ -73,7 +73,7 @@ func TestNewMethod(t *testing.T) {
},
&Field{
Name: "B",
PBFieldName: "b",
QueryParamName: "b",
CamelName: "B",
LowCamelName: "b",
LocalName: "BSum",

Просмотреть файл

@ -116,7 +116,7 @@ func TestGenServerDecode(t *testing.T) {
Fields: []*Field{
&Field{
Name: "a",
PBFieldName: "a",
QueryParamName: "a",
CamelName: "A",
LowCamelName: "a",
LocalName: "ASum",
@ -129,7 +129,7 @@ func TestGenServerDecode(t *testing.T) {
},
&Field{
Name: "b",
PBFieldName: "b",
QueryParamName: "b",
CamelName: "B",
LowCamelName: "b",
LocalName: "BSum",

Просмотреть файл

@ -35,10 +35,8 @@ type Binding struct {
// Field contains the distillation of information within an svcdef.Field that's
// useful for templating http transport.
type Field struct {
Name string
// PBFieldName 'snake_case' in `protobuf:"varint,1,opt,name=snake_case,json=snakeCase" json:"snake_case,omitempty"`
// Where Name is 'SnakeCase'
PBFieldName string
Name string
QueryParamName string
// The name of this field, but passed through the CamelCase function.
// Removes underscores, adds camelcase; "client_id" becomes "ClientId".
CamelName string

Просмотреть файл

@ -74,8 +74,9 @@ type ServiceMethod struct {
// Field represents a field on a protobuf message.
type Field struct {
Name string
// PBFieldName 'snake_case' in `protobuf:"varint,1,opt,name=snake_case,json=snakeCase" json:"snake_case,omitempty"`
// Where Name is 'SnakeCase'
// PBFieldName is the string value of the field name in the definition .proto file.
// For Example: 'snake_case' from below -- where Name would be 'SnakeCase'
// `protobuf:"varint,1,opt,name=snake_case,json=snakeCase" json:"snake_case,omitempty"`
PBFieldName string
Type *FieldType
}