diff --git a/tool/sql2go/parser.go b/tool/sql2go/parser.go index 6cbb3a0..8c0b203 100644 --- a/tool/sql2go/parser.go +++ b/tool/sql2go/parser.go @@ -8,6 +8,7 @@ package sql2go import ( + "errors" "strings" "git.zhangdeman.cn/zhangdeman/gopkg/util" @@ -54,7 +55,10 @@ func ParseCreateTableSql(sql string) (string, *BasicTableInfo, error) { return "", nil, err } - r := stmt.(*sqlparser.DDL) + r, ok := stmt.(*sqlparser.DDL) + if !ok { + return "", nil, errors.New("input sql is not ddl") + } basic.TableName = sqlparser.String(r.NewName) basic.ModelStruct = util.SnakeCaseToCamel(basic.TableName) structResult := "type " + basic.ModelStruct + " struct { \n"