Compare commits
No commits in common. "main" and "v0.0.99" have entirely different histories.
|
@ -3,8 +3,6 @@
|
|||
package infra
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
@ -15,8 +13,7 @@ var Response Reply
|
|||
type Reply struct {
|
||||
Code int32 `json:"code"` // 响应码
|
||||
Message string `json:"message"` // 响应消息
|
||||
Details any `json:"details"` // 响应数据
|
||||
Timeseq int64 `json:"timeseq"` // 时间戳序列
|
||||
Result any `json:"result"` // 响应数据
|
||||
}
|
||||
|
||||
// Success 返回成功响应
|
||||
|
@ -24,11 +21,10 @@ type Reply struct {
|
|||
// data: 响应数据
|
||||
func (reply *Reply) Success(ctx *gin.Context, data any) {
|
||||
reply.Code = 0
|
||||
reply.Details = data
|
||||
reply.Result = data
|
||||
reply.Message = ""
|
||||
reply.Timeseq = time.Now().UnixMilli()
|
||||
if data == nil {
|
||||
reply.Details = ""
|
||||
reply.Result = ""
|
||||
}
|
||||
ctx.JSON(200, reply)
|
||||
}
|
||||
|
@ -38,7 +34,7 @@ func (reply *Reply) Success(ctx *gin.Context, data any) {
|
|||
// err: 错误对象
|
||||
func (reply *Reply) Error(ctx *gin.Context, err error) {
|
||||
reply.Code = 500
|
||||
reply.Details = ""
|
||||
reply.Result = ""
|
||||
// 默认状态码为500
|
||||
e, ok := status.FromError(err)
|
||||
if ok {
|
||||
|
|
|
@ -41,23 +41,6 @@ var (
|
|||
once sync.Once
|
||||
)
|
||||
|
||||
// 初始化Logger配置
|
||||
func New(cfg *conf.LogConf) {
|
||||
if cfg == nil {
|
||||
cfg = &conf.LogConf{
|
||||
Name: strings.ToLower(vars.ServiceKey),
|
||||
Level: vars.LogLevel(vars.DEBUG),
|
||||
Dir: "./logs/",
|
||||
Endpoint: "",
|
||||
Console: true,
|
||||
File: true,
|
||||
Remote: false,
|
||||
}
|
||||
}
|
||||
|
||||
InitLogger(cfg)
|
||||
}
|
||||
|
||||
// InitLogger 初始化全局日志器
|
||||
func InitLogger(cfg *conf.LogConf) error {
|
||||
var err error
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package with
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/conf"
|
||||
"git.apinb.com/bsm-sdk/core/logger"
|
||||
"git.apinb.com/bsm-sdk/core/vars"
|
||||
)
|
||||
|
||||
// 初始化Logger配置
|
||||
func Logger(cfg *conf.LogConf) {
|
||||
if cfg == nil {
|
||||
cfg = &conf.LogConf{
|
||||
Name: strings.ToLower(vars.ServiceKey),
|
||||
Level: vars.LogLevel(vars.DEBUG),
|
||||
Dir: "./logs/",
|
||||
Endpoint: "",
|
||||
Console: true,
|
||||
File: true,
|
||||
Remote: false,
|
||||
}
|
||||
}
|
||||
|
||||
logger.InitLogger(cfg)
|
||||
}
|
Loading…
Reference in New Issue