Merge pull request #32 from maxbad/v2.0

logic返回有错误代码时,标记为错误日志
This commit is contained in:
孟帅 2023-05-31 17:07:48 +08:00 committed by GitHub
commit 46604b51b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 5 deletions

View File

@ -59,7 +59,7 @@ var (
var cmd = server
simple.SafeGo(ctx, func(ctx context.Context) {
if err := cmd.Func(ctx, parser); err != nil {
g.Log().Fatal(ctx, "%v start fail:", cmd.Name, err)
g.Log().Fatalf(ctx, "%v start fail:%v", cmd.Name, err)
}
})
}

View File

@ -19,7 +19,7 @@ const (
LogicWhereComments = "\n\t// 查询%s\n"
LogicWhereNoSupport = "\t// TODO 暂不支持生成[ %s ]查询方式,请自行补充此处代码!"
LogicListSimpleSelect = "\tfields, err := hgorm.GenSelect(ctx, sysin.%sListModel{}, dao.%s)\n\tif err != nil {\n\t\treturn\n\t}"
LogicListJoinSelect = "\t//关联表select\n\tfields, err := hgorm.GenJoinSelect(ctx, %sin.%sListModel{}, dao.%s, []*hgorm.Join{\n%v\t})\n\n\tif err != nil {\n\t\treturn\n\t}"
LogicListJoinSelect = "\t//关联表select\n\tfields, err := hgorm.GenJoinSelect(ctx, %sin.%sListModel{}, dao.%s, []*hgorm.Join{\n%v\t})\n\n\tif err != nil {\n\t\terr = gerror.Wrap(err, \"获取%s关联字段失败请稍后重试\")\n\t\treturn\n\t}"
LogicListJoinOnRelation = "\t// 关联表%s\n\tmod = mod.%s(hgorm.GenJoinOnRelation(\n\t\tdao.%s.Table(), dao.%s.Columns().%s, // 主表表名,关联字段\n\t\tdao.%s.Table(), \"%s\", dao.%s.Columns().%s, // 关联表表名,别名,关联字段\n\t)...)\n\n"
LogicEditUpdate = "\tif _, err = s.Model(ctx%s).\n\t\t\tFields(%sin.%sUpdateFields{}).\n\t\t\tWherePri(in.%s).Data(in).Update(); err != nil {\n\t\t\terr = gerror.Wrap(err, \"修改%s失败请稍后重试\")\n\t\t}\n\t\treturn"
LogicEditInsert = "\tif _, err = s.Model(ctx, &handler.Option{FilterAuth: false}).\n\t\tFields(%sin.%sInsertFields{}).\n\t\tData(in).Insert(); err != nil {\n\t\terr = gerror.Wrap(err, \"新增%s失败请稍后重试\")\n\t}"
@ -138,7 +138,7 @@ func (l *gCurd) generateLogicListJoin(ctx context.Context, in *CurdPreviewInput)
}
}
selectBuffer.WriteString(fmt.Sprintf(LogicListJoinSelect, in.options.TemplateGroup, in.In.VarName, in.In.DaoName, joinSelectRows))
selectBuffer.WriteString(fmt.Sprintf(LogicListJoinSelect, in.options.TemplateGroup, in.In.VarName, in.In.DaoName, joinSelectRows, in.In.TableComment))
data["select"] = selectBuffer.String()
data["fields"] = "fields"

View File

@ -101,10 +101,14 @@ func responseJson(r *ghttp.Request) {
if err = r.GetError(); err != nil {
// 记录到自定义错误日志文件
g.Log().Stdout(false).Printf(ctx, "exception:%v", err)
code = gerror.Code(err).Code()
if code == gcode.CodeNil.Code() {
g.Log().Stdout(false).Printf(ctx, "exception:%v", err)
} else {
g.Log().Errorf(ctx, "exception:%v", err)
}
// 是否输出错误到页面
if g.Cfg().MustGet(ctx, "hotgo.debug", true).Bool() {
message = gerror.Current(err).Error()