fix panic problem when the struct has unexported field.

This commit is contained in:
Shirou WAKAYAMA 2014-11-19 12:44:57 +09:00
parent f43456fecf
commit e313827f04
2 changed files with 11 additions and 6 deletions

View File

@ -5,6 +5,7 @@ import (
"database/sql/driver"
"errors"
"fmt"
"go/ast"
"reflect"
"regexp"
"strconv"
@ -550,6 +551,9 @@ func (scope *Scope) createTable() *Scope {
fields := scope.Fields()
scopeType := scope.IndirectValue().Type()
for i := 0; i < scopeType.NumField(); i++ {
if !ast.IsExported(scopeType.Field(i).Name) {
continue
}
for _, field := range scope.fieldFromStruct(scopeType.Field(i), false) {
field = fields[field.DBName]
if field.IsNormal {

View File

@ -125,12 +125,13 @@ func (i *Num) Scan(src interface{}) error {
}
type Animal struct {
Counter uint64 `gorm:"primary_key:yes"`
Name string `sql:"DEFAULT:'galeone'"`
From string //test reserved sql keyword as field name
Age time.Time `sql:"DEFAULT:current_timestamp"`
CreatedAt time.Time
UpdatedAt time.Time
Counter uint64 `gorm:"primary_key:yes"`
Name string `sql:"DEFAULT:'galeone'"`
From string //test reserved sql keyword as field name
Age time.Time `sql:"DEFAULT:current_timestamp"`
unexported string // unexported value
CreatedAt time.Time
UpdatedAt time.Time
}
type Post struct {