Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录
切换导航
C
common-base
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
赵雪如
common-base
Commits
3b61a05a
提交
3b61a05a
authored
4月 29, 2022
作者:
赵雪如
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
style(log): 修改了日志部分 以及fmt代码
上级
14216093
显示空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
44 行增加
和
47 行删除
+44
-47
code.go
pkg/errors/code.go
+15
-16
code_test.go
pkg/errors/code_test.go
+1
-1
log.go
pkg/log/log.go
+15
-15
log_test.go
pkg/log/log_test.go
+6
-5
response.go
pkg/response/response.go
+5
-9
response_test.go
pkg/response/response_test.go
+2
-1
没有找到文件。
pkg/errors/code.go
浏览文件 @
3b61a05a
...
...
@@ -38,7 +38,6 @@ func (c BizCode) Message() string {
return
c
.
M
}
func
(
c
BizCode
)
Detail
()
interface
{}
{
return
c
.
Ref
}
...
...
@@ -73,8 +72,8 @@ func ParseCoder(err error) gcode.Code {
if
coder
,
ok
:=
codes
[
v
.
C
];
ok
{
return
BizCode
{
C
:
coder
.
Code
(),
M
:
strings
.
Replace
(
coder
.
Message
(),
"%%0"
,
v
.
M
,
-
1
),
Ref
:
coder
.
Detail
(),
M
:
strings
.
Replace
(
coder
.
Message
(),
"%%0"
,
v
.
M
,
-
1
),
Ref
:
coder
.
Detail
(),
}
}
}
...
...
@@ -82,10 +81,10 @@ func ParseCoder(err error) gcode.Code {
return
CodeUnknown
}
func
New
(
code
int
,
message
string
,
reference
string
)
error
{
func
New
(
code
int
,
message
string
,
reference
string
)
error
{
return
gerror
.
NewCode
(
BizCode
{
C
:
code
,
M
:
message
,
Ref
:
reference
,
Ref
:
reference
,
})
}
pkg/errors/code_test.go
浏览文件 @
3b61a05a
pkg/log/log.go
浏览文件 @
3b61a05a
...
...
@@ -15,7 +15,7 @@ func init() {
})
}
func
(
w
*
MyWriter
)
Write
(
p
[]
byte
)(
n
int
,
err
error
)
{
func
(
w
*
MyWriter
)
Write
(
p
[]
byte
)
(
n
int
,
err
error
)
{
//s := string(p)
//if gregex.IsMatchString(`PANI|FATA|ERRO`, s) {
// fmt.Println("SERIOUS ISSUE OCCURRED!! I'd better tell monitor in first time!")
...
...
@@ -24,20 +24,20 @@ func (w *MyWriter)Write(p []byte)(n int, err error) {
return
w
.
logger
.
Write
(
p
)
}
type
log
struct
{
Url
string
Request
interface
{}
Respone
interface
{}
Error
string
type
Log
struct
{
Url
string
`json:"Url,omitempty"`
//请求路径
Method
string
`json:"Method,omitempty"`
Request
interface
{}
`json:"Request,omitempty"`
//请求参数
Respone
interface
{}
`json:"Respone,omitempty"`
//响应参数
ResponeTime
interface
{}
`json:"ResponeTime,omitempty"`
//响应时间
Error
error
`json:"Error,omitempty"`
//错误
Ext
interface
{}
`json:"Ext,omitempty"`
//扩展字段
}
func
Info
(
ctx
context
.
Context
,
cat
string
,
url
string
,
req
interface
{},
res
interface
{})
{
info
:=
log
{
Url
:
url
,
Request
:
req
,
Respone
:
res
}
glog
.
Ctx
(
ctx
)
.
Cat
(
cat
)
.
Info
(
info
)
func
Info
(
ctx
context
.
Context
,
cat
string
,
params
*
Log
)
{
glog
.
Ctx
(
ctx
)
.
Cat
(
cat
)
.
Info
(
params
)
}
func
Error
(
ctx
context
.
Context
,
cat
,
url
string
,
req
interface
{},
err
error
)
{
info
:=
log
{
Url
:
url
,
Request
:
req
,
Error
:
err
.
Error
()}
glog
.
Ctx
(
ctx
)
.
Cat
(
cat
)
.
Error
(
info
)
func
Error
(
ctx
context
.
Context
,
cat
string
,
params
*
Log
)
{
glog
.
Ctx
(
ctx
)
.
Cat
(
cat
)
.
Error
(
params
)
}
pkg/log/log_test.go
浏览文件 @
3b61a05a
...
...
@@ -2,14 +2,15 @@ package log
import
(
"context"
"errors"
"github.com/gogf/gf/frame/g"
"gitlab.jxhh.com/zhaoxueru/common-base.git/pkg/errors"
"testing"
)
func
TestLog
(
t
*
testing
.
T
)
{
Error
(
context
.
TODO
(),
"easy"
,
"http://url/com"
,
g
.
Map
{
"a"
:
1
,
},
errors
.
New
(
"yyy"
))
Error
(
context
.
TODO
(),
"easy"
,
&
Log
{
Request
:
g
.
Map
{
"a"
:
1
},
Error
:
errors
.
New
(
100000
,
"wocuole"
,
""
),
})
}
pkg/response/response.go
浏览文件 @
3b61a05a
...
...
@@ -28,15 +28,13 @@ func Json(r *ghttp.Request, code int, message string, data ...interface{}) {
jsonResponse
.
Message
=
message
jsonResponse
.
Data
=
responseData
jsonResponse
.
Id
=
grand
.
S
(
20
)
if
!
r
.
GetCtxVar
(
"RequestId"
)
.
IsNil
(){
if
!
r
.
GetCtxVar
(
"RequestId"
)
.
IsNil
()
{
jsonResponse
.
Id
=
gconv
.
String
(
r
.
GetCtxVar
(
"RequestId"
))
}
r
.
Response
.
WriteJson
(
jsonResponse
)
}
// 返回JSON数据并退出当前HTTP执行函数。
func
Error
(
r
*
ghttp
.
Request
,
err
error
)
{
coder
:=
errors
.
ParseCoder
(
err
)
...
...
@@ -56,5 +54,3 @@ func SuccessWithData(r *ghttp.Request, data interface{}) {
Json
(
r
,
errors
.
CodeSuccess
.
Code
(),
errors
.
CodeSuccess
.
Message
(),
data
)
r
.
Exit
()
}
pkg/response/response_test.go
浏览文件 @
3b61a05a
...
...
@@ -4,6 +4,7 @@ import (
"gitlab.jxhh.com/zhaoxueru/common-base.git/pkg/errors"
"testing"
)
func
init
()
{
errors
.
MustRegister
(
100001
,
"success"
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论