bufanyun / hotgo

HotGo 是一个基于 vue 和 goframe2.0 开发的全栈前后端分离的开发基础平台和移动应用平台,集成jwt鉴权,动态路由,动态菜单,casbin鉴权,消息队列,定时任务等功能,提供多种常用场景文件,让您把更多时间专注在业务开发上。
https://hotgo.facms.cn/admin
MIT License
1.22k stars 314 forks source link

代码生成,按默认配置生成后go编译报错 #41

Open djun opened 1 year ago

djun commented 1 year ago

系统版本:Windows 11 22H2

HotGo版本:2.8.4 (今天重新拉取过最新代码进行测试,还是同样报错)

本机Go版本:1.20.7

目前是在前端“代码生成”菜单中,选取 hg_test_category 这张表,按默认生成配置提交生成代码, 生成后,前端出现新菜单,但后端go编译出错(gf run 运行的),编译报错提示如下:

build: main.go
go build -o ./\main.exe  main.go
build error: 
# hotgo/internal/library/hgorm/handler
internal\library\hgorm\handler\filter_auth.go:88:58: role.CustomDept.Var undefined (type string has no field or method Var)
# hotgo/addons/hgexample/model/input/sysin
addons\hgexample\model\input\sysin\table.go:29:12: in.Map.IsNil undefined (type string has no field or method IsNil)
addons\hgexample\model\input\sysin\table.go:30:12: cannot use gjson.New(consts.NilJsonToString) (value of type *gjson.Json) as string value in assignment
addons\hgexample\model\input\sysin\table.go:32:13: in.Flag.IsNil undefined (type string has no field or method IsNil)
addons\hgexample\model\input\sysin\table.go:33:13: cannot use gjson.New(consts.NilJsonToString) (value of type *gjson.Json) as string value in assignment
addons\hgexample\model\input\sysin\table.go:35:15: in.Images.IsNil undefined (type string has no field or method IsNil)
addons\hgexample\model\input\sysin\table.go:36:15: cannot use gjson.New(consts.NilJsonToString) (value of type *gjson.Json) as string value in assignment
addons\hgexample\model\input\sysin\table.go:38:20: in.Attachfiles.IsNil undefined (type string has no field or method IsNil)
addons\hgexample\model\input\sysin\table.go:39:20: cannot use gjson.New(consts.NilJsonToString) (value of type *gjson.Json) as string value in assignment
addons\hgexample\model\input\sysin\table.go:41:14: in.Hobby.IsNil undefined (type string has no field or method IsNil)
addons\hgexample\model\input\sysin\table.go:42:14: cannot use gjson.New(consts.NilJsonToString) (value of type *gjson.Json) as string value in assignment
addons\hgexample\model\input\sysin\table.go:42:14: too many errors
# hotgo/internal/library/hggen/views
internal\library\hggen\views\curd.go:99:31: in.In.MasterColumns.Scan undefined (type string has no field or method Scan)
internal\library\hggen\views\curd.go:116:25: in.In.Options.Scan undefined (type string has no field or method Scan)
exit status 1

请求解决问题,感激不尽!

djun commented 1 year ago

系统版本:Ubuntu 23.04 (VMWare 虚拟机)

HotGo版本:2.8.4 (今天重新拉取过最新代码进行测试,还是同样报错)

本机Go版本:1.20.3 (Ubuntu仓库中的版本)

一样的操作,报错提示基本一样:

ubuntu@ubuntu-VMware-Virtual-Platform:~/hotgo/server$ go build main.go
# hotgo/internal/library/hgorm/handler
internal/library/hgorm/handler/filter_auth.go:88:58: role.CustomDept.Var undefined (type string has no field or method Var)
# hotgo/addons/hgexample/model/input/sysin
addons/hgexample/model/input/sysin/table.go:29:12: in.Map.IsNil undefined (type string has no field or method IsNil)
addons/hgexample/model/input/sysin/table.go:30:12: cannot use gjson.New(consts.NilJsonToString) (value of type *gjson.Json) as string value in assignment
addons/hgexample/model/input/sysin/table.go:32:13: in.Flag.IsNil undefined (type string has no field or method IsNil)
addons/hgexample/model/input/sysin/table.go:33:13: cannot use gjson.New(consts.NilJsonToString) (value of type *gjson.Json) as string value in assignment
addons/hgexample/model/input/sysin/table.go:35:15: in.Images.IsNil undefined (type string has no field or method IsNil)
addons/hgexample/model/input/sysin/table.go:36:15: cannot use gjson.New(consts.NilJsonToString) (value of type *gjson.Json) as string value in assignment
addons/hgexample/model/input/sysin/table.go:38:20: in.Attachfiles.IsNil undefined (type string has no field or method IsNil)
addons/hgexample/model/input/sysin/table.go:39:20: cannot use gjson.New(consts.NilJsonToString) (value of type *gjson.Json) as string value in assignment
addons/hgexample/model/input/sysin/table.go:41:14: in.Hobby.IsNil undefined (type string has no field or method IsNil)
addons/hgexample/model/input/sysin/table.go:42:14: cannot use gjson.New(consts.NilJsonToString) (value of type *gjson.Json) as string value in assignment
addons/hgexample/model/input/sysin/table.go:42:14: too many errors
# hotgo/internal/library/hggen/views
internal/library/hggen/views/curd.go:99:31: in.In.MasterColumns.Scan undefined (type string has no field or method Scan)
internal/library/hggen/views/curd.go:116:25: in.In.Options.Scan undefined (type string has no field or method Scan)
bufanyun commented 1 year ago

这是你数据库版本不支持json或导入时json类型被转换成text导致的,请确认是mysql5.7及以上版本

djun commented 1 year ago

这是你数据库版本不支持json或导入时json类型被转换成text导致的,请确认是mysql5.7及以上版本

收到,谢谢!已定位到问题确实是json类型被转成了longtext;

这边用的基本都是 MariaDB,GF文档也提到支持 MariaDB (跟 MySQL 使用同款驱动),但官方文档里面确实提到 json 是 longtext 的代名词。。

这边用 MySQL 重新试试。但也希望热狗框架可以同时适配 MariaDB 这个字段类型的情况。万分感激!

相关文档: MariaDB JSON Data Type

bufanyun commented 1 year ago

好的,后续可以考虑适配。短期内仍想使用MariaDB的话需要自行对不兼容的地方做下调整

djun commented 1 year ago

好的,后续可以考虑适配。短期内仍想使用MariaDB的话需要自行对不兼容的地方做下调整

谢谢,本 issue 可先不关闭,后续其他朋友有需要也可以看到