mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-08-26 16:46:14 +08:00
发布v2.15.7版本,更新内容请查看:https://github.com/bufanyun/hotgo/tree/v2.0/docs/guide-zh-CN/addon-version-upgrade.md
This commit is contained in:
@@ -18,12 +18,6 @@ const (
|
||||
EmsTemplateCash = "cash" // 申请提现
|
||||
)
|
||||
|
||||
// 验证码状态
|
||||
const (
|
||||
EmsStatusNotUsed = 1 // 未使用
|
||||
EmsStatusUsed = 2 // 已使用
|
||||
)
|
||||
|
||||
var EmsSubjectMap = g.MapStrStr{
|
||||
EmsTemplateText: "这是一封来自HotGo的邮件",
|
||||
EmsTemplateCode: "验证码",
|
||||
|
@@ -5,6 +5,15 @@
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package consts
|
||||
|
||||
import (
|
||||
"hotgo/internal/library/dict"
|
||||
"hotgo/internal/model"
|
||||
)
|
||||
|
||||
func init() {
|
||||
dict.RegisterEnums("ServerLicenseGroupOptions", "服务授权分组选项", ServerLicenseGroupOptions)
|
||||
}
|
||||
|
||||
// 授权分组
|
||||
const (
|
||||
LicenseGroupDefault = "default" // 默认组
|
||||
@@ -12,8 +21,9 @@ const (
|
||||
LicenseGroupAuth = "auth" // 服务授权
|
||||
)
|
||||
|
||||
var LicenseGroupNameMap = map[string]string{
|
||||
LicenseGroupDefault: "默认组",
|
||||
LicenseGroupCron: "定时任务",
|
||||
LicenseGroupAuth: "服务授权",
|
||||
// ServerLicenseGroupOptions 服务授权分组选项
|
||||
var ServerLicenseGroupOptions = []*model.Option{
|
||||
dict.GenWarningOption(LicenseGroupDefault, "默认组"),
|
||||
dict.GenSuccessOption(LicenseGroupCron, "定时任务"),
|
||||
dict.GenSuccessOption(LicenseGroupAuth, "服务授权"),
|
||||
}
|
||||
|
@@ -6,7 +6,6 @@
|
||||
package consts
|
||||
|
||||
// 短信驱动
|
||||
|
||||
const (
|
||||
SmsDriveAliYun = "aliyun" // 阿里云
|
||||
SmsDriveTencent = "tencent" // 腾讯云
|
||||
@@ -32,9 +31,3 @@ var (
|
||||
SmsTemplateCash: "申请提现",
|
||||
}
|
||||
)
|
||||
|
||||
// 验证码状态
|
||||
const (
|
||||
SmsStatusNotUsed = 1 // 未使用
|
||||
SmsStatusUsed = 2 // 已使用
|
||||
)
|
||||
|
@@ -5,6 +5,16 @@
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package consts
|
||||
|
||||
import (
|
||||
"hotgo/internal/library/dict"
|
||||
"hotgo/internal/model"
|
||||
)
|
||||
|
||||
func init() {
|
||||
dict.RegisterEnums("CodeStatusOptions", "验证码状态选项", CodeStatusOptions)
|
||||
dict.RegisterEnums("BlacklistStatusOptions", "黑名单拉黑状态选项", BlacklistStatusOptions)
|
||||
}
|
||||
|
||||
// 状态码
|
||||
const (
|
||||
StatusALL int = -1 // 全部状态
|
||||
@@ -14,3 +24,26 @@ const (
|
||||
)
|
||||
|
||||
var StatusSlice = []int{StatusALL, StatusEnabled, StatusDisable, StatusDelete}
|
||||
|
||||
// 验证码状态
|
||||
const (
|
||||
CodeStatusNotUsed = 1 // 未使用
|
||||
CodeStatusUsed = 2 // 已使用
|
||||
)
|
||||
|
||||
// CodeStatusOptions 验证码状态选项
|
||||
var CodeStatusOptions = []*model.Option{
|
||||
dict.GenWarningOption(CodeStatusNotUsed, "未使用"),
|
||||
dict.GenSuccessOption(CodeStatusUsed, "已使用"),
|
||||
}
|
||||
|
||||
const (
|
||||
BlacklistStatusDisable = 1 // 封禁中
|
||||
BlacklistStatusEnabled = 2 // 已解封
|
||||
)
|
||||
|
||||
// BlacklistStatusOptions 黑名单拉黑状态选项
|
||||
var BlacklistStatusOptions = []*model.Option{
|
||||
dict.GenWarningOption(BlacklistStatusDisable, "封禁中"),
|
||||
dict.GenSuccessOption(BlacklistStatusEnabled, "已解封"),
|
||||
}
|
||||
|
@@ -7,5 +7,5 @@ package consts
|
||||
|
||||
// VersionApp HotGo版本
|
||||
const (
|
||||
VersionApp = "2.15.1"
|
||||
VersionApp = "2.15.7"
|
||||
)
|
||||
|
@@ -204,16 +204,6 @@ func (c *cMonitor) NetOnlineList(ctx context.Context, req *monitor.NetOnlineList
|
||||
func (c *cMonitor) NetOption(ctx context.Context, req *monitor.NetOptionReq) (res *monitor.NetOptionRes, err error) {
|
||||
res = new(monitor.NetOptionRes)
|
||||
|
||||
// 授权分组
|
||||
for k, v := range consts.LicenseGroupNameMap {
|
||||
res.LicenseGroup = append(res.LicenseGroup, &form.Select{
|
||||
Value: k,
|
||||
Name: v,
|
||||
Label: v,
|
||||
})
|
||||
}
|
||||
sort.Sort(res.LicenseGroup)
|
||||
|
||||
for _, v := range service.TCPServer().Instance().GetRoutes() {
|
||||
// 无需勾选的路由
|
||||
disabled := false
|
||||
|
@@ -8,8 +8,6 @@ package sys
|
||||
import (
|
||||
"context"
|
||||
"hotgo/api/admin/attachment"
|
||||
"hotgo/internal/library/storager"
|
||||
"hotgo/internal/model/input/sysin"
|
||||
"hotgo/internal/service"
|
||||
)
|
||||
|
||||
@@ -50,42 +48,6 @@ func (c *cAttachment) List(ctx context.Context, req *attachment.ListReq) (res *a
|
||||
return
|
||||
}
|
||||
|
||||
// ChooserOption 获取选择器选项
|
||||
func (c *cAttachment) ChooserOption(ctx context.Context, req *attachment.ChooserOptionReq) (res *attachment.ChooserOptionRes, err error) {
|
||||
res = new(attachment.ChooserOptionRes)
|
||||
|
||||
res.Drive, err = service.SysDictData().Select(ctx, &sysin.DataSelectInp{Type: "config_upload_drive"})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var kinds = []attachment.KindSelect{
|
||||
{
|
||||
Label: "全部", Key: "", Value: "",
|
||||
},
|
||||
{
|
||||
Label: "图片", Key: storager.KindImg, Value: storager.KindImg, Icon: "PictureOutlined", Tag: "success",
|
||||
},
|
||||
{
|
||||
Label: "文档", Key: storager.KindDoc, Value: storager.KindDoc, Icon: "FileWordOutlined", Tag: "primary",
|
||||
},
|
||||
{
|
||||
Label: "音频", Key: storager.KindAudio, Value: storager.KindAudio, Icon: "CustomerServiceOutlined", Tag: "info",
|
||||
},
|
||||
{
|
||||
Label: "视频", Key: storager.KindVideo, Value: storager.KindVideo, Icon: "PlaySquareOutlined", Tag: "warning",
|
||||
},
|
||||
{
|
||||
Label: "压缩包", Key: storager.KindZip, Value: storager.KindZip, Icon: "FileZipOutlined", Tag: "error",
|
||||
},
|
||||
{
|
||||
Label: "其他", Key: storager.KindOther, Value: storager.KindOther, Icon: "PlusOutlined", Tag: "default",
|
||||
},
|
||||
}
|
||||
res.Kind = append(res.Kind, kinds...)
|
||||
return
|
||||
}
|
||||
|
||||
// ClearKind 清空上传类型
|
||||
func (c *cAttachment) ClearKind(ctx context.Context, req *attachment.ClearKindReq) (res *attachment.ClearKindRes, err error) {
|
||||
err = service.SysAttachment().ClearKind(ctx, &req.AttachmentClearKindInp)
|
||||
|
@@ -3,7 +3,7 @@
|
||||
// @Copyright Copyright (c) 2024 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
// @AutoGenerate Version 2.13.1
|
||||
// @AutoGenerate Version 2.15.1
|
||||
package sys
|
||||
|
||||
import (
|
||||
@@ -78,8 +78,14 @@ func (c *cCurdDemo) Delete(ctx context.Context, req *curddemo.DeleteReq) (res *c
|
||||
return
|
||||
}
|
||||
|
||||
// Status 更新CURD列表状态
|
||||
func (c *cCurdDemo) Status(ctx context.Context, req *curddemo.StatusReq) (res *curddemo.StatusRes, err error) {
|
||||
err = service.SysCurdDemo().Status(ctx, &req.CurdDemoStatusInp)
|
||||
return
|
||||
}
|
||||
|
||||
// Switch 更新CURD列表开关状态
|
||||
func (c *cCurdDemo) Switch(ctx context.Context, req *curddemo.SwitchReq) (res *curddemo.SwitchRes, err error) {
|
||||
err = service.SysCurdDemo().Switch(ctx, &req.CurdDemoSwitchInp)
|
||||
return
|
||||
}
|
||||
}
|
@@ -3,7 +3,7 @@
|
||||
// @Copyright Copyright (c) 2024 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
// @AutoGenerate Version 2.13.1
|
||||
// @AutoGenerate Version 2.15.1
|
||||
package sys
|
||||
|
||||
import (
|
||||
|
@@ -3,7 +3,7 @@
|
||||
// @Copyright Copyright (c) 2024 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
// @AutoGenerate Version 2.13.1
|
||||
// @AutoGenerate Version 2.15.1
|
||||
package sys
|
||||
|
||||
import (
|
||||
|
@@ -3,7 +3,7 @@
|
||||
// @Copyright Copyright (c) 2024 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
// @AutoGenerate Version 2.13.1
|
||||
// @AutoGenerate Version 2.15.1
|
||||
package sys
|
||||
|
||||
import (
|
||||
|
0
server/internal/dao/addon_hgexample_table.go
Normal file → Executable file
0
server/internal/dao/addon_hgexample_table.go
Normal file → Executable file
0
server/internal/dao/addon_hgexample_tenant_order.go
Normal file → Executable file
0
server/internal/dao/addon_hgexample_tenant_order.go
Normal file → Executable file
0
server/internal/dao/admin_cash.go
Normal file → Executable file
0
server/internal/dao/admin_cash.go
Normal file → Executable file
0
server/internal/dao/admin_credits_log.go
Normal file → Executable file
0
server/internal/dao/admin_credits_log.go
Normal file → Executable file
0
server/internal/dao/admin_dept.go
Normal file → Executable file
0
server/internal/dao/admin_dept.go
Normal file → Executable file
0
server/internal/dao/admin_member.go
Normal file → Executable file
0
server/internal/dao/admin_member.go
Normal file → Executable file
0
server/internal/dao/admin_member_post.go
Normal file → Executable file
0
server/internal/dao/admin_member_post.go
Normal file → Executable file
0
server/internal/dao/admin_member_role.go
Normal file → Executable file
0
server/internal/dao/admin_member_role.go
Normal file → Executable file
0
server/internal/dao/admin_menu.go
Normal file → Executable file
0
server/internal/dao/admin_menu.go
Normal file → Executable file
0
server/internal/dao/admin_notice.go
Normal file → Executable file
0
server/internal/dao/admin_notice.go
Normal file → Executable file
0
server/internal/dao/admin_notice_read.go
Normal file → Executable file
0
server/internal/dao/admin_notice_read.go
Normal file → Executable file
0
server/internal/dao/admin_oauth.go
Normal file → Executable file
0
server/internal/dao/admin_oauth.go
Normal file → Executable file
0
server/internal/dao/admin_order.go
Normal file → Executable file
0
server/internal/dao/admin_order.go
Normal file → Executable file
0
server/internal/dao/admin_post.go
Normal file → Executable file
0
server/internal/dao/admin_post.go
Normal file → Executable file
0
server/internal/dao/admin_role.go
Normal file → Executable file
0
server/internal/dao/admin_role.go
Normal file → Executable file
0
server/internal/dao/admin_role_casbin.go
Normal file → Executable file
0
server/internal/dao/admin_role_casbin.go
Normal file → Executable file
0
server/internal/dao/admin_role_menu.go
Normal file → Executable file
0
server/internal/dao/admin_role_menu.go
Normal file → Executable file
0
server/internal/dao/internal/addon_hgexample_table.go
Normal file → Executable file
0
server/internal/dao/internal/addon_hgexample_table.go
Normal file → Executable file
0
server/internal/dao/internal/addon_hgexample_tenant_order.go
Normal file → Executable file
0
server/internal/dao/internal/addon_hgexample_tenant_order.go
Normal file → Executable file
0
server/internal/dao/internal/admin_cash.go
Normal file → Executable file
0
server/internal/dao/internal/admin_cash.go
Normal file → Executable file
0
server/internal/dao/internal/admin_credits_log.go
Normal file → Executable file
0
server/internal/dao/internal/admin_credits_log.go
Normal file → Executable file
0
server/internal/dao/internal/admin_dept.go
Normal file → Executable file
0
server/internal/dao/internal/admin_dept.go
Normal file → Executable file
0
server/internal/dao/internal/admin_member.go
Normal file → Executable file
0
server/internal/dao/internal/admin_member.go
Normal file → Executable file
0
server/internal/dao/internal/admin_member_post.go
Normal file → Executable file
0
server/internal/dao/internal/admin_member_post.go
Normal file → Executable file
0
server/internal/dao/internal/admin_member_role.go
Normal file → Executable file
0
server/internal/dao/internal/admin_member_role.go
Normal file → Executable file
0
server/internal/dao/internal/admin_menu.go
Normal file → Executable file
0
server/internal/dao/internal/admin_menu.go
Normal file → Executable file
0
server/internal/dao/internal/admin_notice.go
Normal file → Executable file
0
server/internal/dao/internal/admin_notice.go
Normal file → Executable file
0
server/internal/dao/internal/admin_notice_read.go
Normal file → Executable file
0
server/internal/dao/internal/admin_notice_read.go
Normal file → Executable file
0
server/internal/dao/internal/admin_oauth.go
Normal file → Executable file
0
server/internal/dao/internal/admin_oauth.go
Normal file → Executable file
0
server/internal/dao/internal/admin_order.go
Normal file → Executable file
0
server/internal/dao/internal/admin_order.go
Normal file → Executable file
0
server/internal/dao/internal/admin_post.go
Normal file → Executable file
0
server/internal/dao/internal/admin_post.go
Normal file → Executable file
0
server/internal/dao/internal/admin_role.go
Normal file → Executable file
0
server/internal/dao/internal/admin_role.go
Normal file → Executable file
0
server/internal/dao/internal/admin_role_casbin.go
Normal file → Executable file
0
server/internal/dao/internal/admin_role_casbin.go
Normal file → Executable file
0
server/internal/dao/internal/admin_role_menu.go
Normal file → Executable file
0
server/internal/dao/internal/admin_role_menu.go
Normal file → Executable file
0
server/internal/dao/internal/pay_log.go
Normal file → Executable file
0
server/internal/dao/internal/pay_log.go
Normal file → Executable file
0
server/internal/dao/internal/pay_refund.go
Normal file → Executable file
0
server/internal/dao/internal/pay_refund.go
Normal file → Executable file
0
server/internal/dao/internal/sys_addons_config.go
Normal file → Executable file
0
server/internal/dao/internal/sys_addons_config.go
Normal file → Executable file
0
server/internal/dao/internal/sys_attachment.go
Normal file → Executable file
0
server/internal/dao/internal/sys_attachment.go
Normal file → Executable file
0
server/internal/dao/internal/sys_blacklist.go
Normal file → Executable file
0
server/internal/dao/internal/sys_blacklist.go
Normal file → Executable file
0
server/internal/dao/internal/sys_config.go
Normal file → Executable file
0
server/internal/dao/internal/sys_config.go
Normal file → Executable file
0
server/internal/dao/internal/sys_cron.go
Normal file → Executable file
0
server/internal/dao/internal/sys_cron.go
Normal file → Executable file
0
server/internal/dao/internal/sys_cron_group.go
Normal file → Executable file
0
server/internal/dao/internal/sys_cron_group.go
Normal file → Executable file
0
server/internal/dao/internal/sys_dict_data.go
Normal file → Executable file
0
server/internal/dao/internal/sys_dict_data.go
Normal file → Executable file
0
server/internal/dao/internal/sys_dict_type.go
Normal file → Executable file
0
server/internal/dao/internal/sys_dict_type.go
Normal file → Executable file
0
server/internal/dao/internal/sys_ems_log.go
Normal file → Executable file
0
server/internal/dao/internal/sys_ems_log.go
Normal file → Executable file
0
server/internal/dao/internal/sys_gen_codes.go
Normal file → Executable file
0
server/internal/dao/internal/sys_gen_codes.go
Normal file → Executable file
0
server/internal/dao/internal/sys_gen_curd_demo.go
Normal file → Executable file
0
server/internal/dao/internal/sys_gen_curd_demo.go
Normal file → Executable file
0
server/internal/dao/internal/sys_gen_tree_demo.go
Normal file → Executable file
0
server/internal/dao/internal/sys_gen_tree_demo.go
Normal file → Executable file
0
server/internal/dao/internal/sys_log.go
Normal file → Executable file
0
server/internal/dao/internal/sys_log.go
Normal file → Executable file
0
server/internal/dao/internal/sys_login_log.go
Normal file → Executable file
0
server/internal/dao/internal/sys_login_log.go
Normal file → Executable file
0
server/internal/dao/internal/sys_provinces.go
Normal file → Executable file
0
server/internal/dao/internal/sys_provinces.go
Normal file → Executable file
0
server/internal/dao/internal/sys_serve_license.go
Normal file → Executable file
0
server/internal/dao/internal/sys_serve_license.go
Normal file → Executable file
0
server/internal/dao/internal/sys_serve_log.go
Normal file → Executable file
0
server/internal/dao/internal/sys_serve_log.go
Normal file → Executable file
0
server/internal/dao/internal/sys_sms_log.go
Normal file → Executable file
0
server/internal/dao/internal/sys_sms_log.go
Normal file → Executable file
0
server/internal/dao/internal/test_category.go
Normal file → Executable file
0
server/internal/dao/internal/test_category.go
Normal file → Executable file
0
server/internal/dao/pay_log.go
Normal file → Executable file
0
server/internal/dao/pay_log.go
Normal file → Executable file
0
server/internal/dao/pay_refund.go
Normal file → Executable file
0
server/internal/dao/pay_refund.go
Normal file → Executable file
0
server/internal/dao/sys_addons_config.go
Normal file → Executable file
0
server/internal/dao/sys_addons_config.go
Normal file → Executable file
0
server/internal/dao/sys_attachment.go
Normal file → Executable file
0
server/internal/dao/sys_attachment.go
Normal file → Executable file
0
server/internal/dao/sys_blacklist.go
Normal file → Executable file
0
server/internal/dao/sys_blacklist.go
Normal file → Executable file
0
server/internal/dao/sys_config.go
Normal file → Executable file
0
server/internal/dao/sys_config.go
Normal file → Executable file
0
server/internal/dao/sys_cron.go
Normal file → Executable file
0
server/internal/dao/sys_cron.go
Normal file → Executable file
0
server/internal/dao/sys_cron_group.go
Normal file → Executable file
0
server/internal/dao/sys_cron_group.go
Normal file → Executable file
0
server/internal/dao/sys_dict_data.go
Normal file → Executable file
0
server/internal/dao/sys_dict_data.go
Normal file → Executable file
0
server/internal/dao/sys_dict_type.go
Normal file → Executable file
0
server/internal/dao/sys_dict_type.go
Normal file → Executable file
0
server/internal/dao/sys_ems_log.go
Normal file → Executable file
0
server/internal/dao/sys_ems_log.go
Normal file → Executable file
0
server/internal/dao/sys_gen_codes.go
Normal file → Executable file
0
server/internal/dao/sys_gen_codes.go
Normal file → Executable file
0
server/internal/dao/sys_gen_curd_demo.go
Normal file → Executable file
0
server/internal/dao/sys_gen_curd_demo.go
Normal file → Executable file
0
server/internal/dao/sys_gen_tree_demo.go
Normal file → Executable file
0
server/internal/dao/sys_gen_tree_demo.go
Normal file → Executable file
0
server/internal/dao/sys_log.go
Normal file → Executable file
0
server/internal/dao/sys_log.go
Normal file → Executable file
0
server/internal/dao/sys_login_log.go
Normal file → Executable file
0
server/internal/dao/sys_login_log.go
Normal file → Executable file
0
server/internal/dao/sys_provinces.go
Normal file → Executable file
0
server/internal/dao/sys_provinces.go
Normal file → Executable file
0
server/internal/dao/sys_serve_license.go
Normal file → Executable file
0
server/internal/dao/sys_serve_license.go
Normal file → Executable file
0
server/internal/dao/sys_serve_log.go
Normal file → Executable file
0
server/internal/dao/sys_serve_log.go
Normal file → Executable file
0
server/internal/dao/sys_sms_log.go
Normal file → Executable file
0
server/internal/dao/sys_sms_log.go
Normal file → Executable file
0
server/internal/dao/test_category.go
Normal file → Executable file
0
server/internal/dao/test_category.go
Normal file → Executable file
@@ -12,63 +12,111 @@ import (
|
||||
)
|
||||
|
||||
// GenDefaultOption 生成默认表格回显样式
|
||||
func GenDefaultOption(key interface{}, label string) *model.Option {
|
||||
func GenDefaultOption(key interface{}, label string, extra ...any) *model.Option {
|
||||
e := interface{}(nil)
|
||||
if len(extra) > 0 {
|
||||
e = extra[0]
|
||||
}
|
||||
return &model.Option{
|
||||
Key: key,
|
||||
Label: label,
|
||||
Value: key,
|
||||
ListClass: "default",
|
||||
Extra: e,
|
||||
}
|
||||
}
|
||||
|
||||
func GenSuccessOption(key interface{}, label string) *model.Option {
|
||||
func GenSuccessOption(key interface{}, label string, extra ...any) *model.Option {
|
||||
e := interface{}(nil)
|
||||
if len(extra) > 0 {
|
||||
e = extra[0]
|
||||
}
|
||||
return &model.Option{
|
||||
Key: key,
|
||||
Label: label,
|
||||
Value: key,
|
||||
ListClass: "success",
|
||||
Extra: e,
|
||||
}
|
||||
}
|
||||
|
||||
func GenWarningOption(key interface{}, label string) *model.Option {
|
||||
func GenWarningOption(key interface{}, label string, extra ...any) *model.Option {
|
||||
e := interface{}(nil)
|
||||
if len(extra) > 0 {
|
||||
e = extra[0]
|
||||
}
|
||||
return &model.Option{
|
||||
Key: key,
|
||||
Label: label,
|
||||
Value: key,
|
||||
ListClass: "warning",
|
||||
Extra: e,
|
||||
}
|
||||
}
|
||||
|
||||
func GenErrorOption(key interface{}, label string) *model.Option {
|
||||
func GenErrorOption(key interface{}, label string, extra ...any) *model.Option {
|
||||
e := interface{}(nil)
|
||||
if len(extra) > 0 {
|
||||
e = extra[0]
|
||||
}
|
||||
return &model.Option{
|
||||
Key: key,
|
||||
Label: label,
|
||||
Value: key,
|
||||
ListClass: "error",
|
||||
Extra: e,
|
||||
}
|
||||
}
|
||||
|
||||
func GenInfoOption(key interface{}, label string) *model.Option {
|
||||
func GenInfoOption(key interface{}, label string, extra ...any) *model.Option {
|
||||
e := interface{}(nil)
|
||||
if len(extra) > 0 {
|
||||
e = extra[0]
|
||||
}
|
||||
return &model.Option{
|
||||
Key: key,
|
||||
Label: label,
|
||||
Value: key,
|
||||
ListClass: "info",
|
||||
Extra: e,
|
||||
}
|
||||
}
|
||||
|
||||
func GenPrimaryOption(key interface{}, label string, extra ...any) *model.Option {
|
||||
e := interface{}(nil)
|
||||
if len(extra) > 0 {
|
||||
e = extra[0]
|
||||
}
|
||||
return &model.Option{
|
||||
Key: key,
|
||||
Label: label,
|
||||
Value: key,
|
||||
ListClass: "primary",
|
||||
Extra: e,
|
||||
}
|
||||
}
|
||||
|
||||
// GenCustomOption 生成自定义表格回显样式
|
||||
func GenCustomOption(key interface{}, label string, custom string) *model.Option {
|
||||
func GenCustomOption(key interface{}, label string, custom string, extra ...any) *model.Option {
|
||||
e := interface{}(nil)
|
||||
if len(extra) > 0 {
|
||||
e = extra[0]
|
||||
}
|
||||
return &model.Option{
|
||||
Key: key,
|
||||
Label: label,
|
||||
Value: key,
|
||||
ListClass: custom,
|
||||
Extra: e,
|
||||
}
|
||||
}
|
||||
|
||||
// GenHashOption 根据不同label以hash算法生成表格回显样式
|
||||
func GenHashOption(key interface{}, label string) *model.Option {
|
||||
func GenHashOption(key interface{}, label string, extra ...any) *model.Option {
|
||||
e := interface{}(nil)
|
||||
if len(extra) > 0 {
|
||||
e = extra[0]
|
||||
}
|
||||
strings := []string{"default", "primary", "info", "success", "warning", "error"}
|
||||
hash := fnv.New32()
|
||||
|
||||
@@ -84,6 +132,7 @@ func GenHashOption(key interface{}, label string) *model.Option {
|
||||
Label: label,
|
||||
Value: key,
|
||||
ListClass: tag,
|
||||
Extra: e,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +143,7 @@ func GetOptionLabel(ses []*model.Option, key interface{}) string {
|
||||
return v.Label
|
||||
}
|
||||
}
|
||||
return `Unknown`
|
||||
return ``
|
||||
}
|
||||
|
||||
// HasOptionKey 是否存在指定key
|
||||
|
177
server/internal/library/hggen/internal/cmd/cmd_doc.go
Normal file
177
server/internal/library/hggen/internal/cmd/cmd_doc.go
Normal file
@@ -0,0 +1,177 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/v2/encoding/gcompress"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"hotgo/internal/library/hggen/internal/utility/mlog"
|
||||
)
|
||||
|
||||
const (
|
||||
// DocURL is the download address of the document
|
||||
DocURL = "https://github.com/gogf/gf/archive/refs/heads/gh-pages.zip"
|
||||
)
|
||||
|
||||
var (
|
||||
Doc = cDoc{}
|
||||
)
|
||||
|
||||
type cDoc struct {
|
||||
g.Meta `name:"doc" brief:"download https://pages.goframe.org/ to run locally"`
|
||||
}
|
||||
|
||||
type cDocInput struct {
|
||||
g.Meta `name:"doc" config:"gfcli.doc"`
|
||||
Path string `short:"p" name:"path" brief:"download docs directory path, default is \"%temp%/goframe\""`
|
||||
Port int `short:"o" name:"port" brief:"http server port, default is 8080" d:"8080"`
|
||||
Update bool `short:"u" name:"update" brief:"clean docs directory and update docs"`
|
||||
Clean bool `short:"c" name:"clean" brief:"clean docs directory"`
|
||||
Proxy string `short:"x" name:"proxy" brief:"proxy for download, such as https://hub.gitmirror.com/;https://ghproxy.com/;https://ghproxy.net/;https://ghps.cc/"`
|
||||
}
|
||||
|
||||
type cDocOutput struct{}
|
||||
|
||||
func (c cDoc) Index(ctx context.Context, in cDocInput) (out *cDocOutput, err error) {
|
||||
docs := NewDocSetting(ctx, in)
|
||||
mlog.Print("Directory where the document is downloaded:", docs.TempDir)
|
||||
if in.Clean {
|
||||
mlog.Print("Cleaning document directory")
|
||||
err = docs.Clean()
|
||||
if err != nil {
|
||||
mlog.Print("Failed to clean document directory:", err)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
if in.Update {
|
||||
mlog.Print("Cleaning old document directory")
|
||||
err = docs.Clean()
|
||||
if err != nil {
|
||||
mlog.Print("Failed to clean old document directory:", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
err = docs.DownloadDoc()
|
||||
if err != nil {
|
||||
mlog.Print("Failed to download document:", err)
|
||||
return
|
||||
}
|
||||
s := g.Server()
|
||||
s.SetServerRoot(docs.DocDir)
|
||||
s.SetPort(in.Port)
|
||||
s.SetDumpRouterMap(false)
|
||||
mlog.Printf("Access address http://127.0.0.1:%d", in.Port)
|
||||
s.Run()
|
||||
return
|
||||
}
|
||||
|
||||
// DocSetting doc setting
|
||||
type DocSetting struct {
|
||||
TempDir string
|
||||
DocURL string
|
||||
DocDir string
|
||||
DocZipFile string
|
||||
}
|
||||
|
||||
// NewDocSetting new DocSetting
|
||||
func NewDocSetting(ctx context.Context, in cDocInput) *DocSetting {
|
||||
fileName := "gf-doc-md.zip"
|
||||
tempDir := in.Path
|
||||
if tempDir == "" {
|
||||
tempDir = gfile.Temp("goframe/docs")
|
||||
} else {
|
||||
tempDir = gfile.Abs(path.Join(tempDir, "docs"))
|
||||
}
|
||||
|
||||
return &DocSetting{
|
||||
TempDir: filepath.FromSlash(tempDir),
|
||||
DocDir: filepath.FromSlash(path.Join(tempDir, "gf-gh-pages")),
|
||||
DocURL: in.Proxy + DocURL,
|
||||
DocZipFile: filepath.FromSlash(path.Join(tempDir, fileName)),
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Clean clean the temporary directory
|
||||
func (d *DocSetting) Clean() error {
|
||||
if _, err := os.Stat(d.TempDir); err == nil {
|
||||
err = gfile.Remove(d.TempDir)
|
||||
if err != nil {
|
||||
mlog.Print("Failed to delete temporary directory:", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DownloadDoc download the document
|
||||
func (d *DocSetting) DownloadDoc() error {
|
||||
if _, err := os.Stat(d.TempDir); err != nil {
|
||||
err = gfile.Mkdir(d.TempDir)
|
||||
if err != nil {
|
||||
mlog.Print("Failed to create temporary directory:", err)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
// Check if the file exists
|
||||
if _, err := os.Stat(d.DocDir); err == nil {
|
||||
mlog.Print("Document already exists, no need to download and unzip")
|
||||
return nil
|
||||
}
|
||||
|
||||
if _, err := os.Stat(d.DocZipFile); err == nil {
|
||||
mlog.Print("File already exists, no need to download")
|
||||
} else {
|
||||
mlog.Printf("File does not exist, start downloading: %s", d.DocURL)
|
||||
startTime := time.Now()
|
||||
// Download the file
|
||||
resp, err := http.Get(d.DocURL)
|
||||
if err != nil {
|
||||
mlog.Print("Failed to download file:", err)
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
// Create the file
|
||||
out, err := os.Create(d.DocZipFile)
|
||||
if err != nil {
|
||||
mlog.Print("Failed to create file:", err)
|
||||
return err
|
||||
}
|
||||
defer out.Close()
|
||||
|
||||
// Write the response body to the file
|
||||
_, err = io.Copy(out, resp.Body)
|
||||
if err != nil {
|
||||
mlog.Print("Failed to write file:", err)
|
||||
return err
|
||||
}
|
||||
mlog.Printf("Download successful, time-consuming: %v", time.Since(startTime))
|
||||
}
|
||||
|
||||
mlog.Print("Start unzipping the file...")
|
||||
// Unzip the file
|
||||
err := gcompress.UnZipFile(d.DocZipFile, d.TempDir)
|
||||
if err != nil {
|
||||
mlog.Print("Failed to unzip the file, please run again:", err)
|
||||
gfile.Remove(d.DocZipFile)
|
||||
return err
|
||||
}
|
||||
|
||||
mlog.Print("Download and unzip successful")
|
||||
return nil
|
||||
}
|
@@ -8,6 +8,7 @@ package cmd
|
||||
|
||||
import (
|
||||
//_ "github.com/gogf/gf/contrib/drivers/clickhouse/v2"
|
||||
// _ "github.com/gogf/gf/contrib/drivers/dm/v2" // precompilation does not support certain target platforms.
|
||||
//_ "github.com/gogf/gf/contrib/drivers/mssql/v2"
|
||||
_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
|
||||
//_ "github.com/gogf/gf/contrib/drivers/oracle/v2"
|
||||
|
@@ -19,9 +19,9 @@ import (
|
||||
"github.com/gogf/gf/v2/os/gres"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"github.com/gogf/gf/v2/util/gtag"
|
||||
|
||||
"hotgo/internal/library/hggen/internal/utility/allyes"
|
||||
"hotgo/internal/library/hggen/internal/utility/mlog"
|
||||
"hotgo/internal/library/hggen/internal/utility/utils"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -34,13 +34,15 @@ type cInit struct {
|
||||
}
|
||||
|
||||
const (
|
||||
cInitRepoPrefix = `github.com/gogf/`
|
||||
cInitMonoRepo = `template-mono`
|
||||
cInitSingleRepo = `template-single`
|
||||
cInitBrief = `create and initialize an empty GoFrame project`
|
||||
cInitEg = `
|
||||
cInitRepoPrefix = `github.com/gogf/`
|
||||
cInitMonoRepo = `template-mono`
|
||||
cInitMonoRepoApp = `template-mono-app`
|
||||
cInitSingleRepo = `template-single`
|
||||
cInitBrief = `create and initialize an empty GoFrame project`
|
||||
cInitEg = `
|
||||
gf init my-project
|
||||
gf init my-mono-repo -m
|
||||
gf init my-mono-repo -a
|
||||
`
|
||||
cInitNameBrief = `
|
||||
name for the project. It will create a folder with NAME in current directory.
|
||||
@@ -61,11 +63,12 @@ func init() {
|
||||
}
|
||||
|
||||
type cInitInput struct {
|
||||
g.Meta `name:"init"`
|
||||
Name string `name:"NAME" arg:"true" v:"required" brief:"{cInitNameBrief}"`
|
||||
Mono bool `name:"mono" short:"m" brief:"initialize a mono-repo instead a single-repo" orphan:"true"`
|
||||
Update bool `name:"update" short:"u" brief:"update to the latest goframe version" orphan:"true"`
|
||||
Module string `name:"module" short:"g" brief:"custom go module"`
|
||||
g.Meta `name:"init"`
|
||||
Name string `name:"NAME" arg:"true" v:"required" brief:"{cInitNameBrief}"`
|
||||
Mono bool `name:"mono" short:"m" brief:"initialize a mono-repo instead a single-repo" orphan:"true"`
|
||||
MonoApp bool `name:"monoApp" short:"a" brief:"initialize a mono-repo-app instead a single-repo" orphan:"true"`
|
||||
Update bool `name:"update" short:"u" brief:"update to the latest goframe version" orphan:"true"`
|
||||
Module string `name:"module" short:"g" brief:"custom go module"`
|
||||
}
|
||||
|
||||
type cInitOutput struct{}
|
||||
@@ -86,11 +89,15 @@ func (c cInit) Index(ctx context.Context, in cInitInput) (out *cInitOutput, err
|
||||
templateRepoName string
|
||||
gitignoreFile = in.Name + "/" + cInitGitignore
|
||||
)
|
||||
|
||||
if in.Mono {
|
||||
templateRepoName = cInitMonoRepo
|
||||
} else if in.MonoApp {
|
||||
templateRepoName = cInitMonoRepoApp
|
||||
} else {
|
||||
templateRepoName = cInitSingleRepo
|
||||
}
|
||||
|
||||
err = gres.Export(templateRepoName, in.Name, gres.ExportOption{
|
||||
RemovePrefix: templateRepoName,
|
||||
})
|
||||
@@ -101,7 +108,8 @@ func (c cInit) Index(ctx context.Context, in cInitInput) (out *cInitOutput, err
|
||||
// build ignoreFiles from the .gitignore file
|
||||
ignoreFiles := make([]string, 0, 10)
|
||||
ignoreFiles = append(ignoreFiles, cInitGitDir)
|
||||
if overwrote {
|
||||
// in.MonoApp is a mono-repo-app, it should ignore the .gitignore file
|
||||
if overwrote && !in.MonoApp {
|
||||
err = gfile.ReadLines(gitignoreFile, func(line string) error {
|
||||
// Add only hidden files or directories
|
||||
// If other directories are added, it may cause the entire directory to be ignored
|
||||
@@ -118,10 +126,14 @@ func (c cInit) Index(ctx context.Context, in cInitInput) (out *cInitOutput, err
|
||||
}
|
||||
}
|
||||
|
||||
// Replace module name.
|
||||
// Get template name and module name.
|
||||
if in.Module == "" {
|
||||
in.Module = gfile.Basename(gfile.RealPath(in.Name))
|
||||
}
|
||||
if in.MonoApp {
|
||||
pwd := gfile.Pwd() + string(os.PathSeparator) + in.Name
|
||||
in.Module = utils.GetImportPath(pwd)
|
||||
}
|
||||
|
||||
// Replace template name to project name.
|
||||
err = gfile.ReplaceDirFunc(func(path, content string) string {
|
||||
|
@@ -63,7 +63,7 @@ func init() {
|
||||
}
|
||||
|
||||
type cPackInput struct {
|
||||
g.Meta `name:"pack"`
|
||||
g.Meta `name:"pack" config:"gfcli.pack"`
|
||||
Src string `name:"SRC" arg:"true" v:"required" brief:"{cPackSrcBrief}"`
|
||||
Dst string `name:"DST" arg:"true" v:"required" brief:"{cPackDstBrief}"`
|
||||
Name string `name:"name" short:"n" brief:"{cPackNameBrief}"`
|
||||
|
@@ -9,6 +9,7 @@ package cmd
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
@@ -55,7 +56,7 @@ The "run" command is used for running go codes with hot-compiled-like feature,
|
||||
which compiles and runs the go codes asynchronously when codes change.
|
||||
`
|
||||
cRunFileBrief = `building file path.`
|
||||
cRunPathBrief = `output directory path for built binary file. it's "manifest/output" in default`
|
||||
cRunPathBrief = `output directory path for built binary file. it's "./" in default`
|
||||
cRunExtraBrief = `the same options as "go run"/"go build" except some options as follows defined`
|
||||
cRunArgsBrief = `custom arguments for your process`
|
||||
cRunWatchPathsBrief = `watch additional paths for live reload, separated by ",". i.e. "manifest/config/*.yaml"`
|
||||
@@ -81,7 +82,7 @@ func init() {
|
||||
|
||||
type (
|
||||
cRunInput struct {
|
||||
g.Meta `name:"run"`
|
||||
g.Meta `name:"run" config:"gfcli.run"`
|
||||
File string `name:"FILE" arg:"true" brief:"{cRunFileBrief}" v:"required"`
|
||||
Path string `name:"path" short:"p" brief:"{cRunPathBrief}" d:"./"`
|
||||
Extra string `name:"extra" short:"e" brief:"{cRunExtraBrief}"`
|
||||
@@ -104,13 +105,14 @@ func (c cRun) Index(ctx context.Context, in cRunInput) (out *cRunOutput, err err
|
||||
|
||||
app := &cRunApp{
|
||||
File: in.File,
|
||||
Path: in.Path,
|
||||
Path: filepath.FromSlash(in.Path),
|
||||
Options: in.Extra,
|
||||
Args: in.Args,
|
||||
WatchPaths: in.WatchPaths,
|
||||
}
|
||||
dirty := gtype.NewBool()
|
||||
|
||||
var outputPath = app.genOutputPath()
|
||||
callbackFunc := func(event *gfsnotify.Event) {
|
||||
if gfile.ExtName(event.Path) != "go" {
|
||||
return
|
||||
@@ -125,7 +127,7 @@ func (c cRun) Index(ctx context.Context, in cRunInput) (out *cRunOutput, err err
|
||||
gtimer.SetTimeout(ctx, 1500*gtime.MS, func(ctx context.Context) {
|
||||
defer dirty.Set(false)
|
||||
mlog.Printf(`watched file changes: %s`, event.String())
|
||||
app.Run(ctx)
|
||||
app.Run(ctx, outputPath)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -143,24 +145,21 @@ func (c cRun) Index(ctx context.Context, in cRunInput) (out *cRunOutput, err err
|
||||
}
|
||||
}
|
||||
|
||||
go app.Run(ctx)
|
||||
go app.Run(ctx, outputPath)
|
||||
|
||||
gproc.AddSigHandlerShutdown(func(sig os.Signal) {
|
||||
app.End(ctx, sig, outputPath)
|
||||
os.Exit(0)
|
||||
})
|
||||
gproc.Listen()
|
||||
|
||||
select {}
|
||||
}
|
||||
|
||||
func (app *cRunApp) Run(ctx context.Context) {
|
||||
func (app *cRunApp) Run(ctx context.Context, outputPath string) {
|
||||
// Rebuild and run the codes.
|
||||
renamePath := ""
|
||||
mlog.Printf("build: %s", app.File)
|
||||
outputPath := gfile.Join(app.Path, gfile.Name(app.File))
|
||||
if runtime.GOOS == "windows" {
|
||||
outputPath += ".exe"
|
||||
if gfile.Exists(outputPath) {
|
||||
renamePath = outputPath + "~"
|
||||
if err := gfile.Rename(outputPath, renamePath); err != nil {
|
||||
mlog.Print(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// In case of `pipe: too many open files` error.
|
||||
// Build the app.
|
||||
buildCommand := fmt.Sprintf(
|
||||
@@ -198,6 +197,36 @@ func (app *cRunApp) Run(ctx context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
func (app *cRunApp) End(ctx context.Context, sig os.Signal, outputPath string) {
|
||||
// Delete the binary file.
|
||||
// firstly, kill the process.
|
||||
if process != nil {
|
||||
if err := process.Kill(); err != nil {
|
||||
mlog.Debugf("kill process error: %s", err.Error())
|
||||
}
|
||||
}
|
||||
if err := gfile.Remove(outputPath); err != nil {
|
||||
mlog.Printf("delete binary file error: %s", err.Error())
|
||||
} else {
|
||||
mlog.Printf("deleted binary file: %s", outputPath)
|
||||
}
|
||||
}
|
||||
|
||||
func (app *cRunApp) genOutputPath() (outputPath string) {
|
||||
var renamePath string
|
||||
outputPath = gfile.Join(app.Path, gfile.Name(app.File))
|
||||
if runtime.GOOS == "windows" {
|
||||
outputPath += ".exe"
|
||||
if gfile.Exists(outputPath) {
|
||||
renamePath = outputPath + "~"
|
||||
if err := gfile.Rename(outputPath, renamePath); err != nil {
|
||||
mlog.Print(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return filepath.FromSlash(outputPath)
|
||||
}
|
||||
|
||||
func matchWatchPaths(watchPaths []string, eventPath string) bool {
|
||||
for _, path := range watchPaths {
|
||||
absPath, err := filepath.Abs(path)
|
||||
|
@@ -47,7 +47,7 @@ gf tpl parse -p ./template -v values.json -o ./template.parsed
|
||||
|
||||
type (
|
||||
cTplParseInput struct {
|
||||
g.Meta `name:"parse" brief:"{cTplParseBrief}" eg:"{cTplParseEg}"`
|
||||
g.Meta `name:"parse" config:"gfcli.tpl.parse" brief:"{cTplParseBrief}" eg:"{cTplParseEg}"`
|
||||
Path string `name:"path" short:"p" brief:"template file or folder path" v:"required"`
|
||||
Pattern string `name:"pattern" short:"n" brief:"template file pattern when path is a folder, default is:*" d:"*"`
|
||||
Recursive bool `name:"recursive" short:"c" brief:"recursively parsing files if path is folder, default is:true" d:"true"`
|
||||
|
@@ -48,7 +48,7 @@ func init() {
|
||||
}
|
||||
|
||||
type cUpInput struct {
|
||||
g.Meta `name:"up" config:"gfcli.up"`
|
||||
g.Meta `name:"up" config:"gfcli.up"`
|
||||
All bool `name:"all" short:"a" brief:"upgrade both version and cli, auto fix codes" orphan:"true"`
|
||||
Cli bool `name:"cli" short:"c" brief:"also upgrade CLI tool" orphan:"true"`
|
||||
Fix bool `name:"fix" short:"f" brief:"auto fix codes(it only make sense if cli is to be upgraded)" orphan:"true"`
|
||||
@@ -142,8 +142,9 @@ func (c cUp) doUpgradeVersion(ctx context.Context, in cUpInput) (out *doUpgradeV
|
||||
}
|
||||
for _, pkg := range packages {
|
||||
mlog.Printf(`upgrading "%s" from "%s" to "latest"`, pkg.Name, pkg.Version)
|
||||
// go get -u
|
||||
command := fmt.Sprintf(`cd %s && go get -u %s@latest`, dirPath, pkg.Name)
|
||||
mlog.Printf(`running command: go get %s@latest`, pkg.Name)
|
||||
// go get @latest
|
||||
command := fmt.Sprintf(`cd %s && go get %s@latest`, dirPath, pkg.Name)
|
||||
if err = gproc.ShellRun(ctx, command); err != nil {
|
||||
return
|
||||
}
|
||||
|
@@ -41,9 +41,7 @@ func Test_Gen_Ctrl_Default(t *testing.T) {
|
||||
defer gfile.Remove(path)
|
||||
|
||||
_, err = genctrl.CGenCtrl{}.Ctrl(ctx, in)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
t.AssertNil(err)
|
||||
|
||||
// apiInterface file
|
||||
var (
|
||||
@@ -84,3 +82,228 @@ func Test_Gen_Ctrl_Default(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func expectFilesContent(t *gtest.T, paths []string, expectPaths []string) {
|
||||
for i, expectFile := range expectPaths {
|
||||
val := gfile.GetContents(paths[i])
|
||||
expect := gfile.GetContents(expectFile)
|
||||
t.Assert(val, expect)
|
||||
}
|
||||
}
|
||||
|
||||
// gf gen ctrl -m
|
||||
// In the same module, different API files are added
|
||||
func Test_Gen_Ctrl_UseMerge_AddNewFile(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var (
|
||||
ctrlPath = gfile.Temp(guid.S())
|
||||
//ctrlPath = gtest.DataPath("issue", "3460", "controller")
|
||||
apiFolder = gtest.DataPath("genctrl-merge", "add_new_file", "api")
|
||||
in = genctrl.CGenCtrlInput{
|
||||
SrcFolder: apiFolder,
|
||||
DstFolder: ctrlPath,
|
||||
Merge: true,
|
||||
}
|
||||
)
|
||||
const testNewApiFile = `
|
||||
package v1
|
||||
import "github.com/gogf/gf/v2/frame/g"
|
||||
type DictTypeAddReq struct {
|
||||
g.Meta
|
||||
}
|
||||
type DictTypeAddRes struct {
|
||||
}
|
||||
`
|
||||
|
||||
err := gfile.Mkdir(ctrlPath)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(ctrlPath)
|
||||
|
||||
_, err = genctrl.CGenCtrl{}.Ctrl(ctx, in)
|
||||
t.AssertNil(err)
|
||||
|
||||
var (
|
||||
genApi = filepath.Join(apiFolder, "/dict/dict.go")
|
||||
genApiExpect = filepath.Join(apiFolder, "/dict/dict_expect.go")
|
||||
)
|
||||
defer gfile.Remove(genApi)
|
||||
t.Assert(gfile.GetContents(genApi), gfile.GetContents(genApiExpect))
|
||||
|
||||
genCtrlFiles, err := gfile.ScanDir(ctrlPath, "*.go", true)
|
||||
t.AssertNil(err)
|
||||
t.Assert(genCtrlFiles, []string{
|
||||
filepath.Join(ctrlPath, "/dict/dict.go"),
|
||||
filepath.Join(ctrlPath, "/dict/dict_new.go"),
|
||||
filepath.Join(ctrlPath, "/dict/dict_v1_dict_type.go"),
|
||||
})
|
||||
|
||||
expectCtrlPath := gtest.DataPath("genctrl-merge", "add_new_file", "controller")
|
||||
expectFiles := []string{
|
||||
filepath.Join(expectCtrlPath, "/dict/dict.go"),
|
||||
filepath.Join(expectCtrlPath, "/dict/dict_new.go"),
|
||||
filepath.Join(expectCtrlPath, "/dict/dict_v1_dict_type.go"),
|
||||
}
|
||||
|
||||
// Line Feed maybe \r\n or \n
|
||||
expectFilesContent(t, genCtrlFiles, expectFiles)
|
||||
|
||||
// Add a new API file
|
||||
newApiFilePath := filepath.Join(apiFolder, "/dict/v1/test_new.go")
|
||||
err = gfile.PutContents(newApiFilePath, testNewApiFile)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(newApiFilePath)
|
||||
|
||||
// Then execute the command
|
||||
_, err = genctrl.CGenCtrl{}.Ctrl(ctx, in)
|
||||
t.AssertNil(err)
|
||||
|
||||
genApi = filepath.Join(apiFolder, "/dict.go")
|
||||
genApiExpect = filepath.Join(apiFolder, "/dict_add_new_ctrl_expect.gotest")
|
||||
|
||||
t.Assert(gfile.GetContents(genApi), gfile.GetContents(genApiExpect))
|
||||
|
||||
genCtrlFiles = append(genCtrlFiles, filepath.Join(ctrlPath, "/dict/dict_v1_test_new.go"))
|
||||
// Use the gotest suffix, otherwise the IDE will delete the import
|
||||
expectFiles = append(expectFiles, filepath.Join(expectCtrlPath, "/dict/dict_v1_test_new.gotest"))
|
||||
// Line Feed maybe \r\n or \n
|
||||
expectFilesContent(t, genCtrlFiles, expectFiles)
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
// gf gen ctrl -m
|
||||
// In the same module, Add the same file to the API
|
||||
func Test_Gen_Ctrl_UseMerge_AddNewCtrl(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var (
|
||||
ctrlPath = gfile.Temp(guid.S())
|
||||
//ctrlPath = gtest.DataPath("issue", "3460", "controller")
|
||||
apiFolder = gtest.DataPath("genctrl-merge", "add_new_ctrl", "api")
|
||||
in = genctrl.CGenCtrlInput{
|
||||
SrcFolder: apiFolder,
|
||||
DstFolder: ctrlPath,
|
||||
Merge: true,
|
||||
}
|
||||
)
|
||||
|
||||
err := gfile.Mkdir(ctrlPath)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(ctrlPath)
|
||||
|
||||
_, err = genctrl.CGenCtrl{}.Ctrl(ctx, in)
|
||||
t.AssertNil(err)
|
||||
|
||||
var (
|
||||
genApi = filepath.Join(apiFolder, "/dict/dict.go")
|
||||
genApiExpect = filepath.Join(apiFolder, "/dict/dict_expect.go")
|
||||
)
|
||||
defer gfile.Remove(genApi)
|
||||
t.Assert(gfile.GetContents(genApi), gfile.GetContents(genApiExpect))
|
||||
|
||||
genCtrlFiles, err := gfile.ScanDir(ctrlPath, "*.go", true)
|
||||
t.AssertNil(err)
|
||||
t.Assert(genCtrlFiles, []string{
|
||||
filepath.Join(ctrlPath, "/dict/dict.go"),
|
||||
filepath.Join(ctrlPath, "/dict/dict_new.go"),
|
||||
filepath.Join(ctrlPath, "/dict/dict_v1_dict_type.go"),
|
||||
})
|
||||
|
||||
expectCtrlPath := gtest.DataPath("genctrl-merge", "add_new_ctrl", "controller")
|
||||
expectFiles := []string{
|
||||
filepath.Join(expectCtrlPath, "/dict/dict.go"),
|
||||
filepath.Join(expectCtrlPath, "/dict/dict_new.go"),
|
||||
filepath.Join(expectCtrlPath, "/dict/dict_v1_dict_type.go"),
|
||||
}
|
||||
|
||||
// Line Feed maybe \r\n or \n
|
||||
expectFilesContent(t, genCtrlFiles, expectFiles)
|
||||
|
||||
const testNewApiFile = `
|
||||
|
||||
type DictTypeAddReq struct {
|
||||
g.Meta
|
||||
}
|
||||
type DictTypeAddRes struct {
|
||||
}
|
||||
`
|
||||
dictModuleFileName := filepath.Join(apiFolder, "/dict/v1/dict_type.go")
|
||||
// Save the contents of the file before the changes
|
||||
apiFileContents := gfile.GetContents(dictModuleFileName)
|
||||
|
||||
// Add a new API file
|
||||
err = gfile.PutContentsAppend(dictModuleFileName, testNewApiFile)
|
||||
t.AssertNil(err)
|
||||
|
||||
//==================================
|
||||
// Then execute the command
|
||||
_, err = genctrl.CGenCtrl{}.Ctrl(ctx, in)
|
||||
t.AssertNil(err)
|
||||
|
||||
genApi = filepath.Join(apiFolder, "/dict.go")
|
||||
genApiExpect = filepath.Join(apiFolder, "/dict_add_new_ctrl_expect.gotest")
|
||||
t.Assert(gfile.GetContents(genApi), gfile.GetContents(genApiExpect))
|
||||
|
||||
// Use the gotest suffix, otherwise the IDE will delete the import
|
||||
expectFiles[2] = filepath.Join(expectCtrlPath, "/dict/dict_v1_test_new.gotest")
|
||||
// Line Feed maybe \r\n or \n
|
||||
expectFilesContent(t, genCtrlFiles, expectFiles)
|
||||
|
||||
// Restore the contents of the original API file
|
||||
err = gfile.PutContents(dictModuleFileName, apiFileContents)
|
||||
t.AssertNil(err)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
// https://github.com/gogf/gf/issues/3460
|
||||
func Test_Gen_Ctrl_UseMerge_Issue3460(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var (
|
||||
ctrlPath = gfile.Temp(guid.S())
|
||||
//ctrlPath = gtest.DataPath("issue", "3460", "controller")
|
||||
apiFolder = gtest.DataPath("issue", "3460", "api")
|
||||
in = genctrl.CGenCtrlInput{
|
||||
SrcFolder: apiFolder,
|
||||
DstFolder: ctrlPath,
|
||||
WatchFile: "",
|
||||
SdkPath: "",
|
||||
SdkStdVersion: false,
|
||||
SdkNoV1: false,
|
||||
Clear: false,
|
||||
Merge: true,
|
||||
}
|
||||
)
|
||||
|
||||
err := gfile.Mkdir(ctrlPath)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(ctrlPath)
|
||||
|
||||
_, err = genctrl.CGenCtrl{}.Ctrl(ctx, in)
|
||||
t.AssertNil(err)
|
||||
|
||||
files, err := gfile.ScanDir(ctrlPath, "*.go", true)
|
||||
t.AssertNil(err)
|
||||
t.Assert(files, []string{
|
||||
filepath.Join(ctrlPath, "/hello/hello.go"),
|
||||
filepath.Join(ctrlPath, "/hello/hello_new.go"),
|
||||
filepath.Join(ctrlPath, "/hello/hello_v1_req.go"),
|
||||
filepath.Join(ctrlPath, "/hello/hello_v2_req.go"),
|
||||
})
|
||||
|
||||
expectCtrlPath := gtest.DataPath("issue", "3460", "controller")
|
||||
expectFiles := []string{
|
||||
filepath.Join(expectCtrlPath, "/hello/hello.go"),
|
||||
filepath.Join(expectCtrlPath, "/hello/hello_new.go"),
|
||||
filepath.Join(expectCtrlPath, "/hello/hello_v1_req.go"),
|
||||
filepath.Join(expectCtrlPath, "/hello/hello_v2_req.go"),
|
||||
}
|
||||
|
||||
// Line Feed maybe \r\n or \n
|
||||
for i, expectFile := range expectFiles {
|
||||
val := gfile.GetContents(files[i])
|
||||
expect := gfile.GetContents(expectFile)
|
||||
t.Assert(val, expect)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@@ -12,6 +12,8 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gcfg"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
@@ -69,6 +71,7 @@ func Test_Gen_Dao_Default(t *testing.T) {
|
||||
NoModelComment: false,
|
||||
Clear: false,
|
||||
TypeMapping: nil,
|
||||
FieldMapping: nil,
|
||||
}
|
||||
)
|
||||
err = gutil.FillStructWithDefault(&in)
|
||||
@@ -169,6 +172,7 @@ func Test_Gen_Dao_TypeMapping(t *testing.T) {
|
||||
Import: "github.com/shopspring/decimal",
|
||||
},
|
||||
},
|
||||
FieldMapping: nil,
|
||||
}
|
||||
)
|
||||
err = gutil.FillStructWithDefault(&in)
|
||||
@@ -211,6 +215,108 @@ func Test_Gen_Dao_TypeMapping(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Gen_Dao_FieldMapping(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var (
|
||||
err error
|
||||
db = testDB
|
||||
table = "table_user"
|
||||
sqlContent = fmt.Sprintf(
|
||||
gtest.DataContent(`gendao`, `user.tpl.sql`),
|
||||
table,
|
||||
)
|
||||
)
|
||||
defer dropTableWithDb(db, table)
|
||||
array := gstr.SplitAndTrim(sqlContent, ";")
|
||||
for _, v := range array {
|
||||
if _, err = db.Exec(ctx, v); err != nil {
|
||||
t.AssertNil(err)
|
||||
}
|
||||
}
|
||||
defer dropTableWithDb(db, table)
|
||||
|
||||
var (
|
||||
path = gfile.Temp(guid.S())
|
||||
group = "test"
|
||||
in = gendao.CGenDaoInput{
|
||||
Path: path,
|
||||
Link: link,
|
||||
Tables: "",
|
||||
TablesEx: "",
|
||||
Group: group,
|
||||
Prefix: "",
|
||||
RemovePrefix: "",
|
||||
JsonCase: "",
|
||||
ImportPrefix: "",
|
||||
DaoPath: "",
|
||||
DoPath: "",
|
||||
EntityPath: "",
|
||||
TplDaoIndexPath: "",
|
||||
TplDaoInternalPath: "",
|
||||
TplDaoDoPath: "",
|
||||
TplDaoEntityPath: "",
|
||||
StdTime: false,
|
||||
WithTime: false,
|
||||
GJsonSupport: false,
|
||||
OverwriteDao: false,
|
||||
DescriptionTag: false,
|
||||
NoJsonTag: false,
|
||||
NoModelComment: false,
|
||||
Clear: false,
|
||||
TypeMapping: map[gendao.DBFieldTypeName]gendao.CustomAttributeType{
|
||||
"int": {
|
||||
Type: "int64",
|
||||
Import: "",
|
||||
},
|
||||
},
|
||||
FieldMapping: map[gendao.DBTableFieldName]gendao.CustomAttributeType{
|
||||
"table_user.score": {
|
||||
Type: "decimal.Decimal",
|
||||
Import: "github.com/shopspring/decimal",
|
||||
},
|
||||
},
|
||||
}
|
||||
)
|
||||
err = gutil.FillStructWithDefault(&in)
|
||||
t.AssertNil(err)
|
||||
|
||||
err = gfile.Mkdir(path)
|
||||
t.AssertNil(err)
|
||||
|
||||
// for go mod import path auto retrieve.
|
||||
err = gfile.Copy(
|
||||
gtest.DataPath("gendao", "go.mod.txt"),
|
||||
gfile.Join(path, "go.mod"),
|
||||
)
|
||||
t.AssertNil(err)
|
||||
|
||||
_, err = gendao.CGenDao{}.Dao(ctx, in)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(path)
|
||||
|
||||
// files
|
||||
files, err := gfile.ScanDir(path, "*.go", true)
|
||||
t.AssertNil(err)
|
||||
t.Assert(files, []string{
|
||||
filepath.FromSlash(path + "/dao/internal/table_user.go"),
|
||||
filepath.FromSlash(path + "/dao/table_user.go"),
|
||||
filepath.FromSlash(path + "/model/do/table_user.go"),
|
||||
filepath.FromSlash(path + "/model/entity/table_user.go"),
|
||||
})
|
||||
// content
|
||||
testPath := gtest.DataPath("gendao", "generated_user_field_mapping")
|
||||
expectFiles := []string{
|
||||
filepath.FromSlash(testPath + "/dao/internal/table_user.go"),
|
||||
filepath.FromSlash(testPath + "/dao/table_user.go"),
|
||||
filepath.FromSlash(testPath + "/model/do/table_user.go"),
|
||||
filepath.FromSlash(testPath + "/model/entity/table_user.go"),
|
||||
}
|
||||
for i, _ := range files {
|
||||
t.Assert(gfile.GetContents(files[i]), gfile.GetContents(expectFiles[i]))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func execSqlFile(db gdb.DB, filePath string, args ...any) error {
|
||||
sqlContent := fmt.Sprintf(
|
||||
gfile.GetContents(filePath),
|
||||
@@ -225,6 +331,7 @@ func execSqlFile(db gdb.DB, filePath string, args ...any) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// https://github.com/gogf/gf/issues/2572
|
||||
func Test_Gen_Dao_Issue2572(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var (
|
||||
@@ -244,7 +351,7 @@ func Test_Gen_Dao_Issue2572(t *testing.T) {
|
||||
group = "test"
|
||||
in = gendao.CGenDaoInput{
|
||||
Path: path,
|
||||
Link: link,
|
||||
Link: "",
|
||||
Tables: "",
|
||||
TablesEx: "",
|
||||
Group: group,
|
||||
@@ -268,6 +375,7 @@ func Test_Gen_Dao_Issue2572(t *testing.T) {
|
||||
NoModelComment: false,
|
||||
Clear: false,
|
||||
TypeMapping: nil,
|
||||
FieldMapping: nil,
|
||||
}
|
||||
)
|
||||
err = gutil.FillStructWithDefault(&in)
|
||||
@@ -293,17 +401,26 @@ func Test_Gen_Dao_Issue2572(t *testing.T) {
|
||||
for i, generatedFile := range generatedFiles {
|
||||
generatedFiles[i] = gstr.TrimLeftStr(generatedFile, path)
|
||||
}
|
||||
t.Assert(gstr.InArray(generatedFiles, "/dao/internal/user_1.go"), true)
|
||||
t.Assert(gstr.InArray(generatedFiles, "/dao/internal/user_2.go"), true)
|
||||
t.Assert(gstr.InArray(generatedFiles, "/dao/user_1.go"), true)
|
||||
t.Assert(gstr.InArray(generatedFiles, "/dao/user_2.go"), true)
|
||||
t.Assert(gstr.InArray(generatedFiles, "/model/do/user_1.go"), true)
|
||||
t.Assert(gstr.InArray(generatedFiles, "/model/do/user_2.go"), true)
|
||||
t.Assert(gstr.InArray(generatedFiles, "/model/entity/user_1.go"), true)
|
||||
t.Assert(gstr.InArray(generatedFiles, "/model/entity/user_2.go"), true)
|
||||
t.Assert(gstr.InArray(generatedFiles,
|
||||
filepath.FromSlash("/dao/internal/user_1.go")), true)
|
||||
t.Assert(gstr.InArray(generatedFiles,
|
||||
filepath.FromSlash("/dao/internal/user_2.go")), true)
|
||||
t.Assert(gstr.InArray(generatedFiles,
|
||||
filepath.FromSlash("/dao/user_1.go")), true)
|
||||
t.Assert(gstr.InArray(generatedFiles,
|
||||
filepath.FromSlash("/dao/user_2.go")), true)
|
||||
t.Assert(gstr.InArray(generatedFiles,
|
||||
filepath.FromSlash("/model/do/user_1.go")), true)
|
||||
t.Assert(gstr.InArray(generatedFiles,
|
||||
filepath.FromSlash("/model/do/user_2.go")), true)
|
||||
t.Assert(gstr.InArray(generatedFiles,
|
||||
filepath.FromSlash("/model/entity/user_1.go")), true)
|
||||
t.Assert(gstr.InArray(generatedFiles,
|
||||
filepath.FromSlash("/model/entity/user_2.go")), true)
|
||||
})
|
||||
}
|
||||
|
||||
// https://github.com/gogf/gf/issues/2616
|
||||
func Test_Gen_Dao_Issue2616(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var (
|
||||
@@ -323,7 +440,7 @@ func Test_Gen_Dao_Issue2616(t *testing.T) {
|
||||
group = "test"
|
||||
in = gendao.CGenDaoInput{
|
||||
Path: path,
|
||||
Link: link,
|
||||
Link: "",
|
||||
Tables: "",
|
||||
TablesEx: "",
|
||||
Group: group,
|
||||
@@ -347,6 +464,7 @@ func Test_Gen_Dao_Issue2616(t *testing.T) {
|
||||
NoModelComment: false,
|
||||
Clear: false,
|
||||
TypeMapping: nil,
|
||||
FieldMapping: nil,
|
||||
}
|
||||
)
|
||||
err = gutil.FillStructWithDefault(&in)
|
||||
@@ -372,14 +490,22 @@ func Test_Gen_Dao_Issue2616(t *testing.T) {
|
||||
for i, generatedFile := range generatedFiles {
|
||||
generatedFiles[i] = gstr.TrimLeftStr(generatedFile, path)
|
||||
}
|
||||
t.Assert(gstr.InArray(generatedFiles, "/dao/internal/user_1.go"), true)
|
||||
t.Assert(gstr.InArray(generatedFiles, "/dao/internal/user_2.go"), true)
|
||||
t.Assert(gstr.InArray(generatedFiles, "/dao/user_1.go"), true)
|
||||
t.Assert(gstr.InArray(generatedFiles, "/dao/user_2.go"), true)
|
||||
t.Assert(gstr.InArray(generatedFiles, "/model/do/user_1.go"), true)
|
||||
t.Assert(gstr.InArray(generatedFiles, "/model/do/user_2.go"), true)
|
||||
t.Assert(gstr.InArray(generatedFiles, "/model/entity/user_1.go"), true)
|
||||
t.Assert(gstr.InArray(generatedFiles, "/model/entity/user_2.go"), true)
|
||||
t.Assert(gstr.InArray(generatedFiles,
|
||||
filepath.FromSlash("/dao/internal/user_1.go")), true)
|
||||
t.Assert(gstr.InArray(generatedFiles,
|
||||
filepath.FromSlash("/dao/internal/user_2.go")), true)
|
||||
t.Assert(gstr.InArray(generatedFiles,
|
||||
filepath.FromSlash("/dao/user_1.go")), true)
|
||||
t.Assert(gstr.InArray(generatedFiles,
|
||||
filepath.FromSlash("/dao/user_2.go")), true)
|
||||
t.Assert(gstr.InArray(generatedFiles,
|
||||
filepath.FromSlash("/model/do/user_1.go")), true)
|
||||
t.Assert(gstr.InArray(generatedFiles,
|
||||
filepath.FromSlash("/model/do/user_2.go")), true)
|
||||
t.Assert(gstr.InArray(generatedFiles,
|
||||
filepath.FromSlash("/model/entity/user_1.go")), true)
|
||||
t.Assert(gstr.InArray(generatedFiles,
|
||||
filepath.FromSlash("/model/entity/user_2.go")), true)
|
||||
|
||||
// Key string to check if overwrite the dao files.
|
||||
// dao user1 is not be overwritten as configured in config.yaml.
|
||||
@@ -449,6 +575,7 @@ func Test_Gen_Dao_Issue2746(t *testing.T) {
|
||||
NoModelComment: false,
|
||||
Clear: false,
|
||||
TypeMapping: nil,
|
||||
FieldMapping: nil,
|
||||
}
|
||||
)
|
||||
err = gutil.FillStructWithDefault(&in)
|
||||
@@ -468,3 +595,99 @@ func Test_Gen_Dao_Issue2746(t *testing.T) {
|
||||
t.Assert(expectContent, gfile.GetContents(file))
|
||||
})
|
||||
}
|
||||
|
||||
// https://github.com/gogf/gf/issues/3459
|
||||
func Test_Gen_Dao_Issue3459(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var (
|
||||
err error
|
||||
db = testDB
|
||||
table = "table_user"
|
||||
sqlContent = fmt.Sprintf(
|
||||
gtest.DataContent(`gendao`, `user.tpl.sql`),
|
||||
table,
|
||||
)
|
||||
)
|
||||
dropTableWithDb(db, table)
|
||||
array := gstr.SplitAndTrim(sqlContent, ";")
|
||||
for _, v := range array {
|
||||
if _, err = db.Exec(ctx, v); err != nil {
|
||||
t.AssertNil(err)
|
||||
}
|
||||
}
|
||||
defer dropTableWithDb(db, table)
|
||||
|
||||
var (
|
||||
confDir = gtest.DataPath("issue", "3459")
|
||||
path = gfile.Temp(guid.S())
|
||||
group = "test"
|
||||
in = gendao.CGenDaoInput{
|
||||
Path: path,
|
||||
Link: link,
|
||||
Tables: "",
|
||||
TablesEx: "",
|
||||
Group: group,
|
||||
Prefix: "",
|
||||
RemovePrefix: "",
|
||||
JsonCase: "SnakeScreaming",
|
||||
ImportPrefix: "",
|
||||
DaoPath: "",
|
||||
DoPath: "",
|
||||
EntityPath: "",
|
||||
TplDaoIndexPath: "",
|
||||
TplDaoInternalPath: "",
|
||||
TplDaoDoPath: "",
|
||||
TplDaoEntityPath: "",
|
||||
StdTime: false,
|
||||
WithTime: false,
|
||||
GJsonSupport: false,
|
||||
OverwriteDao: false,
|
||||
DescriptionTag: false,
|
||||
NoJsonTag: false,
|
||||
NoModelComment: false,
|
||||
Clear: false,
|
||||
TypeMapping: nil,
|
||||
}
|
||||
)
|
||||
err = g.Cfg().GetAdapter().(*gcfg.AdapterFile).SetPath(confDir)
|
||||
t.AssertNil(err)
|
||||
|
||||
err = gutil.FillStructWithDefault(&in)
|
||||
t.AssertNil(err)
|
||||
|
||||
err = gfile.Mkdir(path)
|
||||
t.AssertNil(err)
|
||||
|
||||
// for go mod import path auto retrieve.
|
||||
err = gfile.Copy(
|
||||
gtest.DataPath("gendao", "go.mod.txt"),
|
||||
gfile.Join(path, "go.mod"),
|
||||
)
|
||||
t.AssertNil(err)
|
||||
|
||||
_, err = gendao.CGenDao{}.Dao(ctx, in)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(path)
|
||||
|
||||
// files
|
||||
files, err := gfile.ScanDir(path, "*.go", true)
|
||||
t.AssertNil(err)
|
||||
t.Assert(files, []string{
|
||||
filepath.FromSlash(path + "/dao/internal/table_user.go"),
|
||||
filepath.FromSlash(path + "/dao/table_user.go"),
|
||||
filepath.FromSlash(path + "/model/do/table_user.go"),
|
||||
filepath.FromSlash(path + "/model/entity/table_user.go"),
|
||||
})
|
||||
// content
|
||||
testPath := gtest.DataPath("gendao", "generated_user")
|
||||
expectFiles := []string{
|
||||
filepath.FromSlash(testPath + "/dao/internal/table_user.go"),
|
||||
filepath.FromSlash(testPath + "/dao/table_user.go"),
|
||||
filepath.FromSlash(testPath + "/model/do/table_user.go"),
|
||||
filepath.FromSlash(testPath + "/model/entity/table_user.go"),
|
||||
}
|
||||
for i, _ := range files {
|
||||
t.Assert(gfile.GetContents(files[i]), gfile.GetContents(expectFiles[i]))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@@ -8,18 +8,18 @@ package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/gogf/gf/v2/os/gcmd"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"github.com/gogf/gf/v2/util/guid"
|
||||
"github.com/gogf/gf/v2/util/gutil"
|
||||
"hotgo/internal/library/hggen/internal/cmd/genpbentity"
|
||||
)
|
||||
|
||||
func Test_Gen_Pbentity_NameCase(t *testing.T) {
|
||||
func Test_Gen_Pbentity_Default(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var (
|
||||
err error
|
||||
@@ -38,31 +38,171 @@ func Test_Gen_Pbentity_NameCase(t *testing.T) {
|
||||
}
|
||||
}
|
||||
defer dropTableWithDb(db, table)
|
||||
var path = gfile.Temp(guid.S())
|
||||
|
||||
var (
|
||||
path = gfile.Temp(guid.S())
|
||||
in = genpbentity.CGenPbEntityInput{
|
||||
Path: path,
|
||||
Package: "unittest",
|
||||
Link: link,
|
||||
Tables: "",
|
||||
Prefix: "",
|
||||
RemovePrefix: "",
|
||||
RemoveFieldPrefix: "",
|
||||
NameCase: "",
|
||||
JsonCase: "",
|
||||
Option: "",
|
||||
}
|
||||
)
|
||||
err = gutil.FillStructWithDefault(&in)
|
||||
t.AssertNil(err)
|
||||
|
||||
err = gfile.Mkdir(path)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(path)
|
||||
|
||||
root, err := gcmd.NewFromObject(GF)
|
||||
t.AssertNil(err)
|
||||
err = root.AddObject(
|
||||
Gen,
|
||||
)
|
||||
t.AssertNil(err)
|
||||
os.Args = []string{"gf", "gen", "pbentity", "-l", link, "-p", path, "-package=unittest", "-nameCase=SnakeScreaming"}
|
||||
|
||||
err = root.RunWithError(ctx)
|
||||
_, err = genpbentity.CGenPbEntity{}.PbEntity(ctx, in)
|
||||
t.AssertNil(err)
|
||||
|
||||
files := []string{
|
||||
filepath.FromSlash(path + "/table_user.proto"),
|
||||
}
|
||||
// files
|
||||
files, err := gfile.ScanDir(path, "*.proto", false)
|
||||
t.AssertNil(err)
|
||||
t.Assert(files, []string{
|
||||
path + filepath.FromSlash("/table_user.proto"),
|
||||
})
|
||||
|
||||
testPath := gtest.DataPath("genpbentity", "generated_user")
|
||||
// contents
|
||||
testPath := gtest.DataPath("genpbentity", "generated")
|
||||
expectFiles := []string{
|
||||
filepath.FromSlash(testPath + "/table_user.proto"),
|
||||
testPath + filepath.FromSlash("/table_user.proto"),
|
||||
}
|
||||
for i := range files {
|
||||
t.Assert(gfile.GetContents(files[i]), gfile.GetContents(expectFiles[i]))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Gen_Pbentity_NameCase_SnakeScreaming(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var (
|
||||
err error
|
||||
db = testDB
|
||||
table = "table_user"
|
||||
sqlContent = fmt.Sprintf(
|
||||
gtest.DataContent(`genpbentity`, `user.tpl.sql`),
|
||||
table,
|
||||
)
|
||||
)
|
||||
dropTableWithDb(db, table)
|
||||
array := gstr.SplitAndTrim(sqlContent, ";")
|
||||
for _, v := range array {
|
||||
if _, err = db.Exec(ctx, v); err != nil {
|
||||
t.AssertNil(err)
|
||||
}
|
||||
}
|
||||
defer dropTableWithDb(db, table)
|
||||
|
||||
var (
|
||||
path = gfile.Temp(guid.S())
|
||||
in = genpbentity.CGenPbEntityInput{
|
||||
Path: path,
|
||||
Package: "unittest",
|
||||
Link: link,
|
||||
Tables: "",
|
||||
Prefix: "",
|
||||
RemovePrefix: "",
|
||||
RemoveFieldPrefix: "",
|
||||
NameCase: "SnakeScreaming",
|
||||
JsonCase: "",
|
||||
Option: "",
|
||||
}
|
||||
)
|
||||
err = gutil.FillStructWithDefault(&in)
|
||||
t.AssertNil(err)
|
||||
|
||||
err = gfile.Mkdir(path)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(path)
|
||||
|
||||
_, err = genpbentity.CGenPbEntity{}.PbEntity(ctx, in)
|
||||
t.AssertNil(err)
|
||||
|
||||
// files
|
||||
files, err := gfile.ScanDir(path, "*.proto", false)
|
||||
t.AssertNil(err)
|
||||
t.Assert(files, []string{
|
||||
path + filepath.FromSlash("/table_user.proto"),
|
||||
})
|
||||
|
||||
// contents
|
||||
testPath := gtest.DataPath("genpbentity", "generated")
|
||||
expectFiles := []string{
|
||||
testPath + filepath.FromSlash("/table_user_snake_screaming.proto"),
|
||||
}
|
||||
for i := range files {
|
||||
t.Assert(gfile.GetContents(files[i]), gfile.GetContents(expectFiles[i]))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// https://github.com/gogf/gf/issues/3545
|
||||
func Test_Issue_3545(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var (
|
||||
err error
|
||||
db = testDB
|
||||
table = "table_user"
|
||||
sqlContent = fmt.Sprintf(
|
||||
gtest.DataContent(`genpbentity`, `user.tpl.sql`),
|
||||
table,
|
||||
)
|
||||
)
|
||||
dropTableWithDb(db, table)
|
||||
array := gstr.SplitAndTrim(sqlContent, ";")
|
||||
for _, v := range array {
|
||||
if _, err = db.Exec(ctx, v); err != nil {
|
||||
t.AssertNil(err)
|
||||
}
|
||||
}
|
||||
defer dropTableWithDb(db, table)
|
||||
|
||||
var (
|
||||
path = gfile.Temp(guid.S())
|
||||
in = genpbentity.CGenPbEntityInput{
|
||||
Path: path,
|
||||
Package: "",
|
||||
Link: link,
|
||||
Tables: "",
|
||||
Prefix: "",
|
||||
RemovePrefix: "",
|
||||
RemoveFieldPrefix: "",
|
||||
NameCase: "",
|
||||
JsonCase: "",
|
||||
Option: "",
|
||||
}
|
||||
)
|
||||
err = gutil.FillStructWithDefault(&in)
|
||||
t.AssertNil(err)
|
||||
|
||||
err = gfile.Mkdir(path)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(path)
|
||||
|
||||
_, err = genpbentity.CGenPbEntity{}.PbEntity(ctx, in)
|
||||
t.AssertNil(err)
|
||||
|
||||
// files
|
||||
files, err := gfile.ScanDir(path, "*.proto", false)
|
||||
t.AssertNil(err)
|
||||
t.Assert(files, []string{
|
||||
path + filepath.FromSlash("/table_user.proto"),
|
||||
})
|
||||
|
||||
// contents
|
||||
testPath := gtest.DataPath("issue", "3545")
|
||||
expectFiles := []string{
|
||||
testPath + filepath.FromSlash("/table_user.proto"),
|
||||
}
|
||||
// check files content
|
||||
for i := range files {
|
||||
t.Assert(gfile.GetContents(files[i]), gfile.GetContents(expectFiles[i]))
|
||||
}
|
||||
|
@@ -42,9 +42,7 @@ func Test_Gen_Service_Default(t *testing.T) {
|
||||
defer gfile.Remove(path)
|
||||
|
||||
_, err = genservice.CGenService{}.Service(ctx, in)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
t.AssertNil(err)
|
||||
|
||||
// logic file
|
||||
var (
|
||||
@@ -59,12 +57,16 @@ func Test_Gen_Service_Default(t *testing.T) {
|
||||
t.AssertNil(err)
|
||||
t.Assert(files, []string{
|
||||
dstFolder + filepath.FromSlash("/article.go"),
|
||||
dstFolder + filepath.FromSlash("/delivery.go"),
|
||||
dstFolder + filepath.FromSlash("/user.go"),
|
||||
})
|
||||
|
||||
// contents
|
||||
testPath := gtest.DataPath("genservice", "service")
|
||||
expectFiles := []string{
|
||||
testPath + filepath.FromSlash("/article.go"),
|
||||
testPath + filepath.FromSlash("/delivery.go"),
|
||||
testPath + filepath.FromSlash("/user.go"),
|
||||
}
|
||||
for i := range files {
|
||||
t.Assert(gfile.GetContents(files[i]), gfile.GetContents(expectFiles[i]))
|
||||
|
@@ -13,10 +13,8 @@ import (
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"github.com/gogf/gf/v2/text/gregex"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"github.com/gogf/gf/v2/util/gtag"
|
||||
|
||||
"hotgo/internal/library/hggen/internal/utility/mlog"
|
||||
)
|
||||
|
||||
@@ -38,7 +36,6 @@ gf gen ctrl
|
||||
)
|
||||
|
||||
const (
|
||||
PatternApiDefinition = `type[\s\(]+(\w+)Req\s+struct\s+{([\s\S]+?)}`
|
||||
PatternCtrlDefinition = `func\s+\(.+?\)\s+\w+\(.+?\*(\w+)\.(\w+)Req\)\s+\(.+?\*(\w+)\.(\w+)Res,\s+\w+\s+error\)\s+{`
|
||||
)
|
||||
|
||||
@@ -146,7 +143,11 @@ func (c CGenCtrl) generateByWatchFile(watchFile, sdkPath string, sdkStdVersion,
|
||||
}
|
||||
// watch file should have api definitions.
|
||||
if gfile.Exists(watchFile) {
|
||||
if !gregex.IsMatchString(PatternApiDefinition, gfile.GetContents(watchFile)) {
|
||||
structsInfo, err := c.getStructsNameInSrc(watchFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(structsInfo) == 0 {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user