From 9b3be66a7735caed539e1582b0f133596381bb74 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Wed, 30 Jul 2014 15:15:23 +0800 Subject: [PATCH] Refact scope Fields --- scope.go | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/scope.go b/scope.go index 287a803a..cb1313c5 100644 --- a/scope.go +++ b/scope.go @@ -315,24 +315,18 @@ func (scope *Scope) fieldFromStruct(fieldStruct reflect.StructField) *Field { } // Fields get value's fields -func (scope *Scope) Fields() []*Field { - indirectValue := scope.IndirectValue() - fields := []*Field{} - - if !indirectValue.IsValid() { - return fields - } - - scopeTyp := indirectValue.Type() - for i := 0; i < scopeTyp.NumField(); i++ { - fieldStruct := scopeTyp.Field(i) - if !ast.IsExported(fieldStruct.Name) { - continue +func (scope *Scope) Fields() (fields []*Field) { + if scope.IndirectValue().IsValid() { + scopeTyp := scope.IndirectValue().Type() + for i := 0; i < scopeTyp.NumField(); i++ { + fieldStruct := scopeTyp.Field(i) + if !ast.IsExported(fieldStruct.Name) { + continue + } + fields = append(fields, scope.fieldFromStruct(fieldStruct)) } - fields = append(fields, scope.fieldFromStruct(fieldStruct)) } - - return fields + return } // Raw set sql