-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix(autoCode): 目录名称生成改为小驼峰 * feat(autoCode): 方法名调整,按照模块获取模板参数 * feat(autoCode): 支持接口维度自动生成代码 * feat(autoCode): 实例化方式调整 * feat(glog): 日志组件初始版本 * feat(glog): 日志工具ctx赋值去掉 * feat(utils): 数组去重方法 * feat(gcontext): render * feat(gcontext): render中的错误断言调整 * feat(gcontext): render中常量定义 * feat(gcontext): 去掉render中的无用代码 * feat(glog): 结构调整,支持初始化指定日志组件类型 * feat(glog): zap日志组件支持扩展字段 * fear(glog): 字段命名调整 * feat(glog): 增加infow方法 * feat(glog): 日志组件单测
- Loading branch information
Showing
42 changed files
with
1,066 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,5 @@ go.work | |
go.work.sum | ||
|
||
.idea/ | ||
autoCode/tmpAutoCode/* | ||
codeGen/tmpAutoCode/* | ||
glog/log/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package autoCode | ||
package codeGen | ||
|
||
import ( | ||
"gorm.io/gorm" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package autoCode | ||
package codeGen | ||
|
||
import ( | ||
"fmt" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package autoCode | ||
package codeGen | ||
|
||
import ( | ||
"database/sql" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package autoCode | ||
package codeGen | ||
|
||
import ( | ||
"fmt" | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package ginRender | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
"github.com/morehao/go-tools/gcore" | ||
"github.com/morehao/go-tools/gerror" | ||
"github.com/pkg/errors" | ||
"net/http" | ||
) | ||
|
||
func RenderSuccess(ctx *gin.Context, data interface{}) { | ||
r := gcore.NewResponseRender() | ||
r.SetCode(0) | ||
r.SetMsg("success") | ||
r.SetData(data) | ||
ctx.JSON(http.StatusOK, r) | ||
return | ||
} | ||
|
||
func RenderSuccessWithFormat(ctx *gin.Context, data interface{}) { | ||
r := gcore.NewResponseRender() | ||
r.SetCode(0) | ||
r.SetMsg("success") | ||
r.SetDataWithFormat(data) | ||
ctx.JSON(http.StatusOK, r) | ||
return | ||
} | ||
|
||
func RenderFail(ctx *gin.Context, err error) { | ||
r := gcore.NewResponseRender() | ||
|
||
var code int | ||
var msg string | ||
|
||
var gErr gerror.Error | ||
if errors.As(err, &gErr) { | ||
code = gErr.Code | ||
msg = gErr.Msg | ||
} else { | ||
code = -1 | ||
msg = errors.Cause(err).Error() | ||
} | ||
|
||
r.SetCode(code) | ||
r.SetMsg(msg) | ||
r.SetData(gin.H{}) | ||
ctx.JSON(http.StatusOK, r) | ||
return | ||
} | ||
|
||
func RenderAbort(ctx *gin.Context, err error) { | ||
r := gcore.NewResponseRender() | ||
|
||
var gErr gerror.Error | ||
if errors.As(err, &gErr) { | ||
r.SetCode(gErr.Code) | ||
r.SetMsg(gErr.Msg) | ||
r.SetData(gin.H{}) | ||
} else { | ||
r.SetCode(-1) | ||
r.SetMsg(errors.Cause(err).Error()) | ||
r.SetData(gin.H{}) | ||
} | ||
ctx.AbortWithStatusJSON(http.StatusOK, r) | ||
|
||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package gcore | ||
|
||
// ResponseRender 返回数据格式化 | ||
type ResponseRender interface { | ||
SetCode(int) | ||
SetMsg(string) | ||
SetData(interface{}) | ||
SetDataWithFormat(interface{}) | ||
} | ||
|
||
func NewResponseRender() ResponseRender { | ||
return &responseRender{} | ||
} | ||
|
||
type responseRender struct { | ||
Code int `json:"code"` | ||
Msg string `json:"msg"` | ||
Data interface{} `json:"data"` | ||
} | ||
|
||
func (r *responseRender) SetCode(code int) { | ||
r.Code = code | ||
} | ||
func (r *responseRender) SetMsg(msg string) { | ||
r.Msg = msg | ||
} | ||
func (r *responseRender) SetData(data interface{}) { | ||
r.Data = data | ||
} | ||
|
||
func (r *responseRender) SetDataWithFormat(data interface{}) { | ||
ResponseFormat(data) | ||
r.Data = data | ||
} |
Oops, something went wrong.