Commit 56aa224a authored by astaxie's avatar astaxie

simplfy the code

parent 8c37a07a
...@@ -143,7 +143,7 @@ func newFieldInfo(mi *modelInfo, field reflect.Value, sf reflect.StructField, mN ...@@ -143,7 +143,7 @@ func newFieldInfo(mi *modelInfo, field reflect.Value, sf reflect.StructField, mN
var ( var (
tag string tag string
tagValue string tagValue string
initial StrTo initial StrTo // store the default value
fieldType int fieldType int
attrs map[string]bool attrs map[string]bool
tags map[string]string tags map[string]string
...@@ -215,7 +215,7 @@ checkType: ...@@ -215,7 +215,7 @@ checkType:
} }
break checkType break checkType
default: default:
err = fmt.Errorf("error") err = fmt.Errorf("rel only allow these value: fk, one, m2m")
goto wrongTag goto wrongTag
} }
} }
...@@ -235,7 +235,7 @@ checkType: ...@@ -235,7 +235,7 @@ checkType:
} }
break checkType break checkType
default: default:
err = fmt.Errorf("error") err = fmt.Errorf("reverse only allow these value: one, many")
goto wrongTag goto wrongTag
} }
} }
......
...@@ -70,11 +70,8 @@ func getTableEngine(val reflect.Value) string { ...@@ -70,11 +70,8 @@ func getTableEngine(val reflect.Value) string {
fun := val.MethodByName("TableEngine") fun := val.MethodByName("TableEngine")
if fun.IsValid() { if fun.IsValid() {
vals := fun.Call([]reflect.Value{}) vals := fun.Call([]reflect.Value{})
if len(vals) > 0 { if len(vals) > 0 && vals[0].Kind() == reflect.String {
val := vals[0] return vals[0].String()
if val.Kind() == reflect.String {
return val.String()
}
} }
} }
return "" return ""
...@@ -85,15 +82,12 @@ func getTableIndex(val reflect.Value) [][]string { ...@@ -85,15 +82,12 @@ func getTableIndex(val reflect.Value) [][]string {
fun := val.MethodByName("TableIndex") fun := val.MethodByName("TableIndex")
if fun.IsValid() { if fun.IsValid() {
vals := fun.Call([]reflect.Value{}) vals := fun.Call([]reflect.Value{})
if len(vals) > 0 { if len(vals) > 0 && vals[0].CanInterface() {
val := vals[0] if d, ok := vals[0].Interface().([][]string); ok {
if val.CanInterface() {
if d, ok := val.Interface().([][]string); ok {
return d return d
} }
} }
} }
}
return nil return nil
} }
...@@ -102,15 +96,12 @@ func getTableUnique(val reflect.Value) [][]string { ...@@ -102,15 +96,12 @@ func getTableUnique(val reflect.Value) [][]string {
fun := val.MethodByName("TableUnique") fun := val.MethodByName("TableUnique")
if fun.IsValid() { if fun.IsValid() {
vals := fun.Call([]reflect.Value{}) vals := fun.Call([]reflect.Value{})
if len(vals) > 0 { if len(vals) > 0 && vals[0].CanInterface() {
val := vals[0] if d, ok := vals[0].Interface().([][]string); ok {
if val.CanInterface() {
if d, ok := val.Interface().([][]string); ok {
return d return d
} }
} }
} }
}
return nil return nil
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment