From 56aa224a6e2969612a75c37282bc9eb8cdfdd8e4 Mon Sep 17 00:00:00 2001 From: astaxie Date: Wed, 31 Aug 2016 22:47:31 +0800 Subject: [PATCH] simplfy the code --- orm/models_info_f.go | 6 +++--- orm/models_utils.go | 25 ++++++++----------------- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/orm/models_info_f.go b/orm/models_info_f.go index 33db0d4f..ba25f744 100644 --- a/orm/models_info_f.go +++ b/orm/models_info_f.go @@ -143,7 +143,7 @@ func newFieldInfo(mi *modelInfo, field reflect.Value, sf reflect.StructField, mN var ( tag string tagValue string - initial StrTo + initial StrTo // store the default value fieldType int attrs map[string]bool tags map[string]string @@ -215,7 +215,7 @@ checkType: } break checkType default: - err = fmt.Errorf("error") + err = fmt.Errorf("rel only allow these value: fk, one, m2m") goto wrongTag } } @@ -235,7 +235,7 @@ checkType: } break checkType default: - err = fmt.Errorf("error") + err = fmt.Errorf("reverse only allow these value: one, many") goto wrongTag } } diff --git a/orm/models_utils.go b/orm/models_utils.go index 2a1f9d53..44a0e76a 100644 --- a/orm/models_utils.go +++ b/orm/models_utils.go @@ -70,11 +70,8 @@ func getTableEngine(val reflect.Value) string { fun := val.MethodByName("TableEngine") if fun.IsValid() { vals := fun.Call([]reflect.Value{}) - if len(vals) > 0 { - val := vals[0] - if val.Kind() == reflect.String { - return val.String() - } + if len(vals) > 0 && vals[0].Kind() == reflect.String { + return vals[0].String() } } return "" @@ -85,12 +82,9 @@ func getTableIndex(val reflect.Value) [][]string { fun := val.MethodByName("TableIndex") if fun.IsValid() { vals := fun.Call([]reflect.Value{}) - if len(vals) > 0 { - val := vals[0] - if val.CanInterface() { - if d, ok := val.Interface().([][]string); ok { - return d - } + if len(vals) > 0 && vals[0].CanInterface() { + if d, ok := vals[0].Interface().([][]string); ok { + return d } } } @@ -102,12 +96,9 @@ func getTableUnique(val reflect.Value) [][]string { fun := val.MethodByName("TableUnique") if fun.IsValid() { vals := fun.Call([]reflect.Value{}) - if len(vals) > 0 { - val := vals[0] - if val.CanInterface() { - if d, ok := val.Interface().([][]string); ok { - return d - } + if len(vals) > 0 && vals[0].CanInterface() { + if d, ok := vals[0].Interface().([][]string); ok { + return d } } }