Compare commits
No commits in common. "main" and "v0.0.99" have entirely different histories.
|
|
@ -3,8 +3,6 @@
|
||||||
package infra
|
package infra
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"google.golang.org/grpc/status"
|
"google.golang.org/grpc/status"
|
||||||
)
|
)
|
||||||
|
|
@ -15,8 +13,7 @@ var Response Reply
|
||||||
type Reply struct {
|
type Reply struct {
|
||||||
Code int32 `json:"code"` // 响应码
|
Code int32 `json:"code"` // 响应码
|
||||||
Message string `json:"message"` // 响应消息
|
Message string `json:"message"` // 响应消息
|
||||||
Details any `json:"details"` // 响应数据
|
Result any `json:"result"` // 响应数据
|
||||||
Timeseq int64 `json:"timeseq"` // 时间戳序列
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Success 返回成功响应
|
// Success 返回成功响应
|
||||||
|
|
@ -24,11 +21,10 @@ type Reply struct {
|
||||||
// data: 响应数据
|
// data: 响应数据
|
||||||
func (reply *Reply) Success(ctx *gin.Context, data any) {
|
func (reply *Reply) Success(ctx *gin.Context, data any) {
|
||||||
reply.Code = 0
|
reply.Code = 0
|
||||||
reply.Details = data
|
reply.Result = data
|
||||||
reply.Message = ""
|
reply.Message = ""
|
||||||
reply.Timeseq = time.Now().UnixMilli()
|
|
||||||
if data == nil {
|
if data == nil {
|
||||||
reply.Details = ""
|
reply.Result = ""
|
||||||
}
|
}
|
||||||
ctx.JSON(200, reply)
|
ctx.JSON(200, reply)
|
||||||
}
|
}
|
||||||
|
|
@ -38,7 +34,7 @@ func (reply *Reply) Success(ctx *gin.Context, data any) {
|
||||||
// err: 错误对象
|
// err: 错误对象
|
||||||
func (reply *Reply) Error(ctx *gin.Context, err error) {
|
func (reply *Reply) Error(ctx *gin.Context, err error) {
|
||||||
reply.Code = 500
|
reply.Code = 500
|
||||||
reply.Details = ""
|
reply.Result = ""
|
||||||
// 默认状态码为500
|
// 默认状态码为500
|
||||||
e, ok := status.FromError(err)
|
e, ok := status.FromError(err)
|
||||||
if ok {
|
if ok {
|
||||||
|
|
|
||||||
|
|
@ -41,23 +41,6 @@ var (
|
||||||
once sync.Once
|
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 初始化全局日志器
|
// InitLogger 初始化全局日志器
|
||||||
func InitLogger(cfg *conf.LogConf) error {
|
func InitLogger(cfg *conf.LogConf) error {
|
||||||
var err 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